forked from wrenn/wrenn
v0.0.1 (#8)
Co-authored-by: Tasnim Kabir Sadik <tksadik92@gmail.com> Reviewed-on: wrenn/sandbox#8
This commit is contained in:
@ -2,20 +2,43 @@
|
||||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
import { auth } from '$lib/auth.svelte';
|
||||
import { teams } from '$lib/teams.svelte';
|
||||
|
||||
// Check for error in URL params (errors are still passed via query params).
|
||||
const params = $page.url.searchParams;
|
||||
const error = params.get('error');
|
||||
|
||||
function getCookie(name: string): string | null {
|
||||
const match = document.cookie.match(new RegExp(`(?:^|; )${name}=([^;]*)`));
|
||||
return match ? decodeURIComponent(match[1]) : null;
|
||||
}
|
||||
|
||||
function clearOAuthCookies() {
|
||||
for (const name of [
|
||||
'wrenn_oauth_token',
|
||||
'wrenn_oauth_user_id',
|
||||
'wrenn_oauth_team_id',
|
||||
'wrenn_oauth_email',
|
||||
'wrenn_oauth_name'
|
||||
]) {
|
||||
document.cookie = `${name}=; path=/auth/; max-age=0`;
|
||||
}
|
||||
}
|
||||
|
||||
if (error) {
|
||||
goto(`/login?error=${encodeURIComponent(error)}`);
|
||||
} else {
|
||||
const token = params.get('token');
|
||||
const userId = params.get('user_id');
|
||||
const teamId = params.get('team_id');
|
||||
const email = params.get('email');
|
||||
const token = getCookie('wrenn_oauth_token');
|
||||
const userId = getCookie('wrenn_oauth_user_id');
|
||||
const teamId = getCookie('wrenn_oauth_team_id');
|
||||
const email = getCookie('wrenn_oauth_email');
|
||||
const name = getCookie('wrenn_oauth_name') ?? '';
|
||||
|
||||
clearOAuthCookies();
|
||||
|
||||
if (token && userId && teamId && email) {
|
||||
auth.login({ token, user_id: userId, team_id: teamId, email });
|
||||
teams.reset();
|
||||
auth.login({ token, user_id: userId, team_id: teamId, email, name });
|
||||
goto('/dashboard');
|
||||
} else {
|
||||
goto('/login?error=missing_token');
|
||||
@ -24,5 +47,5 @@
|
||||
</script>
|
||||
|
||||
<div class="flex min-h-screen items-center justify-center">
|
||||
<p class="text-[13px] text-[var(--color-text-secondary)]">Signing you in...</p>
|
||||
<p class="text-ui text-[var(--color-text-secondary)]">Signing you in...</p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user