fix login

This commit is contained in:
Hamcha 2023-07-29 16:23:14 +02:00
parent 4254368597
commit 3f1b833c82
Signed by: hamcha
GPG key ID: 1669C533B8CF6D89

View file

@ -1,4 +1,4 @@
import { redirect } from '@sveltejs/kit'; import { HttpError, redirect } from '@sveltejs/kit';
import type { Actions, PageServerLoad } from './$types'; import type { Actions, PageServerLoad } from './$types';
import { APIError } from '$lib/api/request'; import { APIError } from '$lib/api/request';
import { getLoggedInUser, login, logout } from '$lib/api/auth'; import { getLoggedInUser, login, logout } from '$lib/api/auth';
@ -28,7 +28,6 @@ export const actions = {
try { try {
await login(cookies, username, password); await login(cookies, username, password);
throw redirect(302, url.searchParams.get('then') || '/admin');
} catch (e) { } catch (e) {
if (e instanceof APIError) { if (e instanceof APIError) {
switch (e.code) { switch (e.code) {
@ -38,6 +37,7 @@ export const actions = {
} }
return { error: 'unknown internal error' }; return { error: 'unknown internal error' };
} }
throw redirect(302, url.searchParams.get('then') || '/admin');
}, },
logout: async ({ url, cookies }) => { logout: async ({ url, cookies }) => {
await logout(cookies); await logout(cookies);