mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-02-14 20:32:29 +00:00
fix: improve back button handling on auth pages
This commit is contained in:
@@ -33,7 +33,7 @@
|
|||||||
alternativeSignInButton.label = m.sign_in_with_login_code();
|
alternativeSignInButton.label = m.sign_in_with_login_code();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page.url.pathname == '/login') {
|
if (page.url.pathname != '/login') {
|
||||||
alternativeSignInButton.href = `${alternativeSignInButton.href}?redirect=${encodeURIComponent(page.url.pathname + page.url.search)}`;
|
alternativeSignInButton.href = `${alternativeSignInButton.href}?redirect=${encodeURIComponent(page.url.pathname + page.url.search)}`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -179,7 +179,7 @@
|
|||||||
{m.try_again()}
|
{m.try_again()}
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
<Button onclick={() => history.back()} class="flex-1" variant="secondary">
|
<Button href={document.referrer || '/'} class="flex-1" variant="secondary">
|
||||||
{m.cancel()}
|
{m.cancel()}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
import { startAuthentication } from '@simplewebauthn/browser';
|
import { startAuthentication } from '@simplewebauthn/browser';
|
||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
import LoginLogoErrorSuccessIndicator from './components/login-logo-error-success-indicator.svelte';
|
import LoginLogoErrorSuccessIndicator from './components/login-logo-error-success-indicator.svelte';
|
||||||
|
|
||||||
|
let { data } = $props();
|
||||||
|
|
||||||
const webauthnService = new WebAuthnService();
|
const webauthnService = new WebAuthnService();
|
||||||
|
|
||||||
let isLoading = $state(false);
|
let isLoading = $state(false);
|
||||||
@@ -24,7 +27,7 @@
|
|||||||
const user = await webauthnService.finishLogin(authResponse);
|
const user = await webauthnService.finishLogin(authResponse);
|
||||||
|
|
||||||
await userStore.setUser(user);
|
await userStore.setUser(user);
|
||||||
goto('/settings');
|
goto(data.redirect || '/settings');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = getWebauthnErrorMessage(e);
|
error = getWebauthnErrorMessage(e);
|
||||||
}
|
}
|
||||||
|
|||||||
7
frontend/src/routes/login/+page.ts
Normal file
7
frontend/src/routes/login/+page.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import type { PageLoad } from './$types';
|
||||||
|
|
||||||
|
export const load: PageLoad = async ({ url }) => {
|
||||||
|
return {
|
||||||
|
redirect: url.searchParams.get('redirect') || '/settings'
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation';
|
import { afterNavigate, goto } from '$app/navigation';
|
||||||
import { page } from '$app/state';
|
|
||||||
import SignInWrapper from '$lib/components/login-wrapper.svelte';
|
import SignInWrapper from '$lib/components/login-wrapper.svelte';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import Input from '$lib/components/ui/input/input.svelte';
|
import Input from '$lib/components/ui/input/input.svelte';
|
||||||
import { m } from '$lib/paraglide/messages';
|
import { m } from '$lib/paraglide/messages';
|
||||||
import UserService from '$lib/services/user-service';
|
import UserService from '$lib/services/user-service';
|
||||||
import appConfigStore from '$lib/stores/application-configuration-store';
|
|
||||||
import userStore from '$lib/stores/user-store.js';
|
import userStore from '$lib/stores/user-store.js';
|
||||||
import { getAxiosErrorMessage } from '$lib/utils/error-util';
|
import { getAxiosErrorMessage } from '$lib/utils/error-util';
|
||||||
import { preventDefault } from '$lib/utils/event-util';
|
import { preventDefault } from '$lib/utils/event-util';
|
||||||
@@ -17,9 +15,17 @@
|
|||||||
let code = $state(data.code ?? '');
|
let code = $state(data.code ?? '');
|
||||||
let isLoading = $state(false);
|
let isLoading = $state(false);
|
||||||
let error: string | undefined = $state();
|
let error: string | undefined = $state();
|
||||||
|
let backHref = $state('/login/alternative');
|
||||||
|
|
||||||
const userService = new UserService();
|
const userService = new UserService();
|
||||||
|
|
||||||
|
// If the previous page is a Pocket ID page, go back there instead of the generic alternative login page
|
||||||
|
afterNavigate((e) => {
|
||||||
|
if (e.from?.url.pathname) {
|
||||||
|
backHref = e.from.url.pathname + e.from.url.search;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
async function authenticate() {
|
async function authenticate() {
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
try {
|
try {
|
||||||
@@ -64,13 +70,7 @@
|
|||||||
<form onsubmit={preventDefault(authenticate)} class="w-full max-w-[450px]">
|
<form onsubmit={preventDefault(authenticate)} class="w-full max-w-[450px]">
|
||||||
<Input id="Code" class="mt-7" placeholder={m.code()} bind:value={code} type="text" />
|
<Input id="Code" class="mt-7" placeholder={m.code()} bind:value={code} type="text" />
|
||||||
<div class="mt-8 flex justify-between gap-2">
|
<div class="mt-8 flex justify-between gap-2">
|
||||||
<Button
|
<Button variant="secondary" class="flex-1" href={backHref}>{m.go_back()}</Button>
|
||||||
variant="secondary"
|
|
||||||
class="flex-1"
|
|
||||||
href={($appConfigStore.emailOneTimeAccessAsUnauthenticatedEnabled
|
|
||||||
? '/login/alternative'
|
|
||||||
: '/login') + page.url.search}>{m.go_back()}</Button
|
|
||||||
>
|
|
||||||
<Button class="flex-1" type="submit" {isLoading}>{m.submit()}</Button>
|
<Button class="flex-1" type="submit" {isLoading}>{m.submit()}</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user