Skip to content

Commit a368b8a

Browse files
authored
Update account.html
Updates to better improve the new login method
1 parent d999d12 commit a368b8a

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

account.html

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
}
3232
</style>
3333
<script>
34-
function registerUser() {
34+
async function registerUser() {
3535
const username = document.getElementById("username").value.trim();
3636
const messageBox = document.getElementById("message");
3737

@@ -42,18 +42,31 @@
4242

4343
// Base64 encode the redirect URL where Scratch Auth will send the response
4444
const redirectLocation = btoa(window.location.href); // Redirect back to the current page after authentication
45-
46-
// Add specific parameters to the URL to prioritize the "Cloud data" method
47-
const authUrl = `https://auth.itinerary.eu.org/auth/?redirect=${redirectLocation}&name=Scratch Auth Tutorial&sign_in_method=cloud`;
4845

49-
// Display the instructions to the user
50-
messageBox.style.color = "green";
51-
messageBox.textContent = `Redirecting to Scratch Auth... Follow the steps there.`;
46+
// Request to get the token from Scratch Auth's backend
47+
const authUrl = `https://auth-api.itinerary.eu.org/auth/getTokens?redirect=${redirectLocation}&method=cloud&username=${username}`;
5248

53-
// Redirect the user to Scratch Auth after a brief message
54-
setTimeout(() => {
55-
window.location.href = authUrl;
56-
}, 2000); // Delay the redirect for 2 seconds
49+
try {
50+
const response = await fetch(authUrl);
51+
const data = await response.json();
52+
53+
if (data.token) {
54+
// Display the message and redirect user to Scratch Auth
55+
messageBox.style.color = "green";
56+
messageBox.textContent = `Redirecting to Scratch Auth... Follow the steps there.`;
57+
58+
// Redirect to Scratch Auth after a brief delay
59+
setTimeout(() => {
60+
window.location.href = `https://auth.itinerary.eu.org/auth/?redirect=${redirectLocation}&token=${data.token}`;
61+
}, 2000); // Delay of 2 seconds before redirect
62+
} else {
63+
messageBox.style.color = "red";
64+
messageBox.textContent = "Authentication failed. Please try again.";
65+
}
66+
} catch (error) {
67+
messageBox.style.color = "red";
68+
messageBox.textContent = "Error connecting to the authentication service. Please try again later.";
69+
}
5770
}
5871
</script>
5972
</head>
@@ -68,10 +81,10 @@ <h2>Welcome! Please log in to continue.</h2>
6881
<p id="message" class="message"></p>
6982
<p>
7083
Please note: You will be redirected to an external site (Scratch Auth) for authentication. Once there,
71-
choose the "Cloud Data" option for the quickest sign-in method.
84+
follow the on-screen instructions to authenticate.
7285
</p>
7386
<p>
74-
If you are unable to use the "Cloud Data" option, other sign-in methods are available on Scratch Auth's page.
87+
If you face issues, try changing your login method.
7588
</p>
7689
</div>
7790
</body>

0 commit comments

Comments
 (0)