Skip to content

Commit

Permalink
more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jho44 committed Sep 4, 2023
1 parent 250f320 commit f3e5996
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const handle = (async ({ event, resolve }) => {
// }

const cookie = event.cookies.get('session');
console.log(event.url.pathname, cookie);
// check whether authenticated
if (
event.url.pathname !== '/' &&
Expand Down
8 changes: 6 additions & 2 deletions src/routes/login/[phone]/[token]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { redirect } from '@sveltejs/kit';
import prisma from '$lib/prisma';

export const load = (async ({ params, cookies }) => {
console.log('LOAD LOGIN');
let magicLinkInfo;
try {
// validate token against what's stored in the DB
Expand All @@ -11,8 +12,10 @@ export const load = (async ({ params, cookies }) => {
token: params.token
}
});

if (!magicLinkInfo) throw Error;
} catch {
console.error("Can't verify token");
console.error(`Can't verify token ${params.token} for phone ${params.phone}`);
throw redirect(308, `/?phone=${params.phone}`);
}

Expand Down Expand Up @@ -46,14 +49,15 @@ export const load = (async ({ params, cookies }) => {
maxAge: 60 * 60
});

await prisma.session.create({
const session = await prisma.session.create({
data: {
token: sessionToken,
phone,
expires: sessionExpires,
createdAt: sessionCreatedAt
}
});
console.log('CREATED SESSION', session);

throw redirect(308, '/dashboard');
}) satisfies PageServerLoad;

0 comments on commit f3e5996

Please sign in to comment.