Skip to content

Commit 824e1d6

Browse files
authored
update login flow (#2455)
Simplify the login flow. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: evan
1 parent 82ff4e4 commit 824e1d6

File tree

1 file changed

+4
-29
lines changed

1 file changed

+4
-29
lines changed

src/client/jwt.ts

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,6 @@ export function getApiBase() {
3232
}
3333

3434
function getToken(): string | null {
35-
// Check window hash
36-
const { hash } = window.location;
37-
if (hash.startsWith("#")) {
38-
const params = new URLSearchParams(hash.slice(1));
39-
const token = params.get("token");
40-
if (token) {
41-
localStorage.setItem("token", token);
42-
params.delete("token");
43-
params.toString();
44-
}
45-
// Clean the URL
46-
history.replaceState(
47-
null,
48-
"",
49-
window.location.pathname +
50-
window.location.search +
51-
(params.size > 0 ? "#" + params.toString() : ""),
52-
);
53-
}
54-
5535
// Check cookie
5636
const cookie = document.cookie
5737
.split(";")
@@ -83,21 +63,16 @@ export function discordLogin() {
8363
export async function tokenLogin(token: string): Promise<string | null> {
8464
const response = await fetch(
8565
`${getApiBase()}/login/token?login-token=${token}`,
66+
{
67+
credentials: "include",
68+
},
8669
);
8770
if (response.status !== 200) {
8871
console.error("Token login failed", response);
8972
return null;
9073
}
9174
const json = await response.json();
92-
const { jwt, email } = json;
93-
const payload = decodeJwt(jwt);
94-
const result = TokenPayloadSchema.safeParse(payload);
95-
if (!result.success) {
96-
console.error("Invalid token", result.error, result.error.message);
97-
return null;
98-
}
99-
clearToken();
100-
localStorage.setItem("token", jwt);
75+
const { email } = json;
10176
return email;
10277
}
10378

0 commit comments

Comments
 (0)