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 7e6e190 commit 666f2fc
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions src/components/auth.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
import { redirect } from '@sveltejs/kit';

export async function authGuard() {
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);
}
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');
}
}
Expand Down

0 comments on commit 666f2fc

Please sign in to comment.