mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Fixing 2fa
This commit is contained in:
parent
091bcd2e88
commit
8b828d40da
3 changed files with 21 additions and 17 deletions
|
|
@ -13,8 +13,7 @@ import { lucia } from '$lib/server/auth';
|
||||||
// });
|
// });
|
||||||
|
|
||||||
export const authentication: Handle = async function ({ event, resolve }) {
|
export const authentication: Handle = async function ({ event, resolve }) {
|
||||||
const startTimer = Date.now();
|
event.locals.startTimer = Date.now();
|
||||||
event.locals.startTimer = startTimer;
|
|
||||||
|
|
||||||
const ip = event.request.headers.get('x-forwarded-for') as string;
|
const ip = event.request.headers.get('x-forwarded-for') as string;
|
||||||
const country = event.request.headers.get('x-vercel-ip-country') as string;
|
const country = event.request.headers.get('x-vercel-ip-country') as string;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import { add_user_to_role } from '$server/roles';
|
||||||
import db from '../../../db';
|
import db from '../../../db';
|
||||||
import { collections, users, wishlists } from '$db/schema';
|
import { collections, users, wishlists } from '$db/schema';
|
||||||
import { createId as cuid2 } from '@paralleldrive/cuid2';
|
import { createId as cuid2 } from '@paralleldrive/cuid2';
|
||||||
|
import { userFullyAuthenticated, userNotFullyAuthenticated } from '$lib/server/auth-utils';
|
||||||
|
|
||||||
const limiter = new RateLimiter({
|
const limiter = new RateLimiter({
|
||||||
// A rate is defined by [number, unit]
|
// A rate is defined by [number, unit]
|
||||||
|
|
@ -29,16 +30,23 @@ const signUpDefaults = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const load: PageServerLoad = async (event) => {
|
export const load: PageServerLoad = async (event) => {
|
||||||
// redirect(
|
const { locals, cookies } = event;
|
||||||
// 302,
|
const { user, session } = event.locals;
|
||||||
// '/waitlist',
|
|
||||||
// { type: 'error', message: 'Sign-up not yet available. Please add your email to the waitlist!' },
|
|
||||||
// event
|
|
||||||
// );
|
|
||||||
|
|
||||||
if (event.locals.user) {
|
if (userFullyAuthenticated(user, session)) {
|
||||||
const message = { type: 'success', message: 'You are already signed in' } as const;
|
const message = { type: 'success', message: 'You are already signed in' } as const;
|
||||||
throw redirect('/', message, event);
|
throw redirect('/', message, event);
|
||||||
|
} else if (userNotFullyAuthenticated(user, session)) {
|
||||||
|
try {
|
||||||
|
await lucia.invalidateSession(locals.session!.id!);
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Session already invalidated');
|
||||||
|
}
|
||||||
|
const sessionCookie = lucia.createBlankSessionCookie();
|
||||||
|
cookies.set(sessionCookie.name, sessionCookie.value, {
|
||||||
|
path: '.',
|
||||||
|
...sessionCookie.attributes,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -91,8 +99,6 @@ export const actions: Actions = {
|
||||||
verified: false,
|
verified: false,
|
||||||
receive_email: false,
|
receive_email: false,
|
||||||
theme: 'system',
|
theme: 'system',
|
||||||
two_factor_secret: '',
|
|
||||||
two_factor_enabled: false,
|
|
||||||
})
|
})
|
||||||
.returning();
|
.returning();
|
||||||
console.log('signup user', user);
|
console.log('signup user', user);
|
||||||
|
|
@ -104,7 +110,7 @@ export const actions: Actions = {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
add_user_to_role(user[0].id, 'user', true);
|
await add_user_to_role(user[0].id, 'user', true);
|
||||||
await db.insert(collections).values({
|
await db.insert(collections).values({
|
||||||
user_id: user[0].id,
|
user_id: user[0].id,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -77,14 +77,14 @@
|
||||||
|
|
||||||
{#snippet totpForm()}
|
{#snippet totpForm()}
|
||||||
<form method="POST" use:totpEnhance>
|
<form method="POST" use:totpEnhance>
|
||||||
<Form.Field form={totpFormData} name="totpToken">
|
<Form.Field class="form-field-container" form={totpFormData} name="totpToken">
|
||||||
<Form.Control let:attrs>
|
<Form.Control let:attrs>
|
||||||
<Form.Label for="totpToken">TOTP Code</Form.Label>
|
<Form.Label for="totpToken">TOTP Code</Form.Label>
|
||||||
<PinInput {...attrs} bind:value={$totpFormData.totpToken} />
|
<PinInput {...attrs} bind:value={$totpFormData.totpToken} />
|
||||||
</Form.Control>
|
</Form.Control>
|
||||||
<Form.FieldErrors />
|
<Form.FieldErrors />
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
<Form.Button>Submit</Form.Button>
|
<Form.Button class="w-full">Submit</Form.Button>
|
||||||
</form>
|
</form>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
|
|
||||||
|
|
@ -93,11 +93,11 @@
|
||||||
<Form.Field form={recoveryCodeFormData} name="recoveryCode">
|
<Form.Field form={recoveryCodeFormData} name="recoveryCode">
|
||||||
<Form.Control let:attrs>
|
<Form.Control let:attrs>
|
||||||
<Form.Label for="totpToken">Recovery Code</Form.Label>
|
<Form.Label for="totpToken">Recovery Code</Form.Label>
|
||||||
<PinInput {...attrs} bind:value={$recoveryCodeFormData.recoveryCode} inputCount={10} />
|
<Input {...attrs} bind:value={$recoveryCodeFormData.recoveryCode} />
|
||||||
</Form.Control>
|
</Form.Control>
|
||||||
<Form.FieldErrors />
|
<Form.FieldErrors />
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
<Form.Button>Submit</Form.Button>
|
<Form.Button class="w-full">Submit</Form.Button>
|
||||||
</form>
|
</form>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
|
|
||||||
|
|
@ -106,7 +106,6 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
margin-top: 1.5rem;
|
margin-top: 1.5rem;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue