mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-02-04 13:21:45 +00:00
refactor: do not force redirects to happen on the server (#481)
This commit is contained in:
committed by
GitHub
parent
8e66af627a
commit
662506260e
@@ -2,3 +2,7 @@
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
yarn.lock
|
yarn.lock
|
||||||
|
|
||||||
|
# Compiled files
|
||||||
|
.svelte-kit/
|
||||||
|
build/
|
||||||
@@ -27,14 +27,12 @@ const authenticationHandle: Handle = async ({ event, resolve }) => {
|
|||||||
const isPublicPath = ['/authorize', '/health'].includes(event.url.pathname);
|
const isPublicPath = ['/authorize', '/health'].includes(event.url.pathname);
|
||||||
const isAdminPath = event.url.pathname.startsWith('/settings/admin');
|
const isAdminPath = event.url.pathname.startsWith('/settings/admin');
|
||||||
|
|
||||||
if (!isUnauthenticatedOnlyPath && !isPublicPath) {
|
if (!isUnauthenticatedOnlyPath && !isPublicPath && !isSignedIn) {
|
||||||
if (!isSignedIn) {
|
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: 302,
|
status: 302,
|
||||||
headers: { location: '/login' }
|
headers: { location: '/login' }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (isUnauthenticatedOnlyPath && isSignedIn) {
|
if (isUnauthenticatedOnlyPath && isSignedIn) {
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
@@ -81,7 +79,7 @@ function verifyJwt(accessToken: string | undefined) {
|
|||||||
const jwtPayload = decodeJwt<{ isAdmin: boolean }>(accessToken);
|
const jwtPayload = decodeJwt<{ isAdmin: boolean }>(accessToken);
|
||||||
if (jwtPayload?.exp && jwtPayload.exp * 1000 > Date.now()) {
|
if (jwtPayload?.exp && jwtPayload.exp * 1000 > Date.now()) {
|
||||||
isSignedIn = true;
|
isSignedIn = true;
|
||||||
isAdmin = jwtPayload?.isAdmin || false;
|
isAdmin = !!(jwtPayload?.isAdmin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
import { redirect } from '@sveltejs/kit';
|
|
||||||
import type { PageServerLoad } from './$types';
|
|
||||||
|
|
||||||
export const load: PageServerLoad = async () => {
|
|
||||||
return redirect(302, '/login');
|
|
||||||
};
|
|
||||||
6
frontend/src/routes/+page.ts
Normal file
6
frontend/src/routes/+page.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { redirect } from '@sveltejs/kit';
|
||||||
|
import type { PageLoad } from './$types';
|
||||||
|
|
||||||
|
export const load: PageLoad = async () => {
|
||||||
|
return redirect(302, '/login');
|
||||||
|
};
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { redirect } from '@sveltejs/kit';
|
import { redirect } from '@sveltejs/kit';
|
||||||
|
import type { PageLoad } from './$types';
|
||||||
|
|
||||||
// Alias for /login/alternative/code
|
// Alias for /login/alternative/code
|
||||||
export function GET({ url }) {
|
export const load: PageLoad = async ({ url }) => {
|
||||||
let targetPath = '/login/alternative/code';
|
let targetPath = '/login/alternative/code';
|
||||||
if (url.searchParams.has('redirect')) {
|
if (url.searchParams.has('redirect')) {
|
||||||
targetPath += `?redirect=${encodeURIComponent(url.searchParams.get('redirect')!)}`;
|
targetPath += `?redirect=${encodeURIComponent(url.searchParams.get('redirect')!)}`;
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { redirect } from '@sveltejs/kit';
|
import { redirect } from '@sveltejs/kit';
|
||||||
|
import type { PageLoad } from './$types';
|
||||||
|
|
||||||
// Alias for /login/alternative/code?code=...
|
// Alias for /login/alternative/code?code=...
|
||||||
export function GET({ url, params }) {
|
export const load: PageLoad = async ({ url, params }) => {
|
||||||
const targetPath = '/login/alternative/code';
|
const targetPath = '/login/alternative/code';
|
||||||
|
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { PageServerLoad } from './$types';
|
import type { PageLoad } from './$types';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ url }) => {
|
export const load: PageLoad = async ({ url }) => {
|
||||||
return {
|
return {
|
||||||
code: url.searchParams.get('code'),
|
code: url.searchParams.get('code'),
|
||||||
redirect: url.searchParams.get('redirect') || '/settings'
|
redirect: url.searchParams.get('redirect') || '/settings'
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import type { PageServerLoad } from './$types';
|
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ url }) => {
|
|
||||||
return {
|
|
||||||
redirect: url.searchParams.get('redirect') || undefined
|
|
||||||
};
|
|
||||||
};
|
|
||||||
7
frontend/src/routes/login/alternative/email/+page.ts
Normal file
7
frontend/src/routes/login/alternative/email/+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') || undefined
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { redirect } from '@sveltejs/kit';
|
import { redirect } from '@sveltejs/kit';
|
||||||
|
import type { PageLoad } from './$types';
|
||||||
|
|
||||||
export function load() {
|
export const load: PageLoad = async () => {
|
||||||
throw redirect(307, '/settings/account');
|
throw redirect(307, '/settings/account');
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user