Fix login not redirecting
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
import type { Handle } from '@sveltejs/kit';
|
||||
import jws from 'jws';
|
||||
import * as jose from 'jose';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Handle} */
|
||||
export const handle: Handle = async ({ event, resolve }) => {
|
||||
@@ -12,13 +12,13 @@ export const handle: Handle = async ({ event, resolve }) => {
|
||||
event.locals.email = null;
|
||||
return resolve(event);
|
||||
}
|
||||
const jwt = jws.decode(access_token.replace('Bearer ', ''));
|
||||
const jwt = jose.decodeJwt(access_token.replace('Bearer ', ''));
|
||||
if (!jwt) {
|
||||
event.locals.email = null;
|
||||
return resolve(event);
|
||||
}
|
||||
// if token expires, do a request to get a new one and set the response-cookies on the response
|
||||
if (Date.now() >= jwt.payload.exp * 1000) {
|
||||
if (Date.now() >= jwt.exp * 1000) {
|
||||
const res = await fetch(`${process.env.API_URL}/api/v1/users/check`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
@@ -37,6 +37,6 @@ export const handle: Handle = async ({ event, resolve }) => {
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
event.locals.email = jwt.payload.sub;
|
||||
event.locals.email = jwt.sub;
|
||||
return resolve(event);
|
||||
};
|
||||
|
||||
@@ -99,27 +99,27 @@ SPDX-License-Identifier: MPL-2.0
|
||||
{:else if selected_method === null}
|
||||
<!-- <p>SelectWindow</p>-->
|
||||
<div transition:slide|global>
|
||||
<SelectMethod bind:session_data bind:step bind:selected_method />
|
||||
<SelectMethod {session_data} {step} bind:selected_method />
|
||||
</div>
|
||||
{:else if selected_method === 'PASSWORD'}
|
||||
<!-- <p>PasswordWindow</p>-->
|
||||
<div transition:slide|global>
|
||||
<PasswordComponent bind:session_data bind:done bind:step bind:selected_method />
|
||||
<PasswordComponent {session_data} bind:done bind:step bind:selected_method />
|
||||
</div>
|
||||
{:else if selected_method === 'PASSKEY'}
|
||||
<!-- <p>WebauthnWindow</p>-->
|
||||
<div transition:slide|global>
|
||||
<WebauthnComponent bind:session_data bind:done bind:step bind:selected_method />
|
||||
<WebauthnComponent {session_data} bind:done bind:step bind:selected_method />
|
||||
</div>
|
||||
{:else if selected_method === 'BACKUP'}
|
||||
<!-- <p>BackupWindow</p>-->
|
||||
<div transition:slide|global>
|
||||
<BackupComponent bind:session_data bind:done bind:step bind:selected_method />
|
||||
<BackupComponent {session_data} bind:done bind:step bind:selected_method />
|
||||
</div>
|
||||
{:else if selected_method === 'TOTP'}
|
||||
<!-- <p>TotpWindow</p>-->
|
||||
<div transition:slide|global>
|
||||
<TotpComponent bind:session_data bind:done bind:step bind:selected_method />
|
||||
<TotpComponent {session_data} bind:done bind:step bind:selected_method />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -6,19 +6,14 @@ SPDX-License-Identifier: MPL-2.0
|
||||
<script lang="ts">
|
||||
let { session_data = {}, step, selected_method = $bindable() } = $props();
|
||||
|
||||
let available_methods = $state();
|
||||
|
||||
const set_available_methods = (step_var: number) => {
|
||||
const set_available_methods = (step_var: number): string => {
|
||||
if (step_var === 1) {
|
||||
available_methods = session_data.step_1;
|
||||
return session_data.step_1;
|
||||
} else if (step_var === 2) {
|
||||
available_methods = session_data.step_2;
|
||||
return session_data.step_2;
|
||||
}
|
||||
};
|
||||
|
||||
$effect.pre(() => {
|
||||
set_available_methods(step);
|
||||
});
|
||||
let available_methods = $derived(set_available_methods(step));
|
||||
</script>
|
||||
|
||||
<div class="px-6 py-4">
|
||||
|
||||
Reference in New Issue
Block a user