add prev and next to stored state

This commit is contained in:
Erin 2023-11-12 13:02:13 -05:00
parent e553e9ff0b
commit 80415104e5

View file

@ -12,7 +12,7 @@ import {
} from '$lib/server/auth'; } from '$lib/server/auth';
import type {PageServerLoad} from './$types'; import type {PageServerLoad} from './$types';
export const load: PageServerLoad = async ({cookies, params}) => { export const load: PageServerLoad = async ({cookies, params, url}) => {
// figure out what auth provider the user wanted to try // figure out what auth provider the user wanted to try
let provider: AuthProvider; let provider: AuthProvider;
if (params.provider === 'discord') { if (params.provider === 'discord') {
@ -27,7 +27,11 @@ export const load: PageServerLoad = async ({cookies, params}) => {
// store a state for this login attempt // store a state for this login attempt
const authStatesRepo = await dataSource.getRepository(AuthState); const authStatesRepo = await dataSource.getRepository(AuthState);
const state = authStatesRepo.create({provider}); const state = authStatesRepo.create({
provider,
prev: url.searchParams.get('prev') ?? '/',
next: url.searchParams.get('next') ?? '/',
});
await authStatesRepo.save(state); await authStatesRepo.save(state);
// set the state ID as a cookie so we can retrieve it later and compare // set the state ID as a cookie so we can retrieve it later and compare