@@ -32,26 +32,6 @@ export function getApiBase() {
3232}
3333
3434function 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() {
8363export 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