Skip to content

Commit

Permalink
Update auth.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
kwangjong authored Aug 8, 2024
1 parent e4e2aa1 commit 51ba1fd
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions src/components/auth.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import { redirect } from '@sveltejs/kit';

export async function authGuard() {
let tok: string|null = getToken();
if (tok != null) {
await fetch(`https://107106.xyz/auth`, {
method: 'DELETE',
headers: {
'Token': tok,
}
}).then(response => response.status == 401 ? false : true)
.then(pass => {
if (pass) {
return;
} else {
throw redirect(307, '/admin');
}
})
} else {
try {
let tok: string|null = getToken();
if (tok != null) {
await fetch(`https://107106.xyz/auth`, {
method: 'DELETE',
headers: {
'Token': tok,
}
}).then(response => response.status == 401 ? false : true)
.then(pass => {
if (pass) {
return;
} else {
throw redirect(307, '/admin');
}
})
} else {
throw redirect(307, '/admin');
}
} catch (err) {
if (err instanceof Error) {
console.error(err.message);
}
throw redirect(307, '/admin');
}
}
Expand Down Expand Up @@ -53,4 +60,4 @@ export function getToken(): string|null {
.map(cookie => {
return decodeURIComponent(cookie.substring(6));
})[0] || null;
}
}

0 comments on commit 51ba1fd

Please sign in to comment.