|
134 | 134 | };
|
135 | 135 |
|
136 | 136 | function checkAuth() {
|
137 |
| - const authSuccess = new URLSearchParams(window.location.search).get('success'); |
138 |
| - const username = new URLSearchParams(window.location.search).get('username'); |
| 137 | + const PC = new URLSearchParams(window.location.search).get('privateCode'); |
| 138 | + |
| 139 | + if (PC) { |
| 140 | + const res = await fetch(`https://auth-api.itinerary.eu.org/auth/verifyToken/${PC}`); |
| 141 | + const data = await response.json(); |
| 142 | + const username = data.username; |
| 143 | + localStorage.setItem('username', username); |
| 144 | + localStorage.setItem('usernameEnc', btoa(username)); |
| 145 | + localStorage.setItem('loggedIn', 'true') |
| 146 | + |
| 147 | + |
| 148 | + |
139 | 149 |
|
140 |
| - if (username) { |
141 |
| - const decodedUsername = decodeUsername(username); // Decode the username using atob |
142 |
| - localStorage.setItem('usernameEnc', username); // Store the original Base64-encoded username |
143 |
| - localStorage.setItem('loggedIn', 'true'); |
144 |
| - window.location.href = 'index.html'; |
145 | 150 | }
|
146 | 151 |
|
147 | 152 | if (authSuccess === 'true') {
|
|
152 | 157 |
|
153 | 158 | function registerScratchAuth() {
|
154 | 159 | const messageBox = document.getElementById("scratchMessage");
|
155 |
| - const redirectLocation = encodeURIComponent(window.location.href); |
156 |
| - const authUrl = `https://scratchauth-codinghut.onrender.com/auth`; |
| 160 | + const rLocation = btoa(window.location.href); |
| 161 | + const authUrl = `https://auth.itinerary.eu.org/auth?redirect=${location}&name=Scratch%20Coding%20Hut`; |
157 | 162 |
|
158 | 163 | messageBox.style.color = "green";
|
159 | 164 | messageBox.textContent = "Redirecting to ScratchAuth... Follow the steps there.";
|
|
175 | 180 | }
|
176 | 181 |
|
177 | 182 | function logout() {
|
178 |
| - localStorage.removeItem('loggedIn'); |
179 |
| - localStorage.removeItem('username'); |
| 183 | + localStorage.clear(); |
180 | 184 | window.location.href = 'account.html';
|
181 | 185 | }
|
182 | 186 |
|
|
0 commit comments