Skip to content

Commit

Permalink
fix(oauth): redirect already authenticated users
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiDood committed Jul 11, 2024
1 parent bd38e26 commit 2db3433
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/routes/oauth/callback/+server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import { parse } from 'valibot';

const fetchJwks = createRemoteJWKSet(new URL('https://www.googleapis.com/oauth2/v3/certs'));

// eslint-disable-next-line func-style
export async function GET({ fetch, locals: { db }, cookies, url: { searchParams } }) {
// TODO: check if the session already exists
const sid = cookies.get('sid');
if (!sid) redirect(302, '/');
if (typeof sid === 'undefined') redirect(302, '/oauth/login/');

const state = searchParams.get('state');
if (state === null) error(400);
Expand All @@ -33,7 +31,7 @@ export async function GET({ fetch, locals: { db }, cookies, url: { searchParams

const expires = await db.begin(async db => {
const pending = await db.deletePendingSession(sid);
if (pending === null) error(400);
if (pending === null) redirect(302, '/oauth/login/');

const res = await fetch('https://oauth2.googleapis.com/token', {
method: 'POST',
Expand Down

0 comments on commit 2db3433

Please sign in to comment.