refactor viewer-login page with error messages and validation
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
import { dev } from '$app/environment';
|
||||
import { loginUser, logoutUser } from '$lib/server/authService';
|
||||
import { fail, redirect } from '@sveltejs/kit';
|
||||
import { error, fail, redirect } from '@sveltejs/kit';
|
||||
import { ROUTE_NAMES } from '../index.js';
|
||||
import { vorgangPINValidation } from '$lib/server/vorgangService.js';
|
||||
|
||||
export const actions = {
|
||||
login: ({ request, cookies }) => loginUser({ request, cookies }),
|
||||
logout: (event) => logoutUser(event),
|
||||
getVorgangByToken: async ({ request, cookies }) => {
|
||||
default: async ({ request, cookies }) => {
|
||||
const data = await request.formData();
|
||||
const vorgangToken = data.get('vorgang-token');
|
||||
const vorgangPIN = data.get('vorgang-pin') as string;
|
||||
|
||||
if (!vorgangToken || !vorgangPIN) {
|
||||
return fail(400, { message: 'Token oder PIN fehlen' });
|
||||
if (!vorgangPIN) {
|
||||
return fail(400, { message: 'Bitte einen PIN eingeben.'});
|
||||
}
|
||||
|
||||
if (!vorgangPINValidation(vorgangToken, vorgangPIN)) {
|
||||
return fail(400, { message: 'Falsche Zugangsdaten.'});
|
||||
}
|
||||
|
||||
const COOKIE_NAME = `token-${vorgangToken}`;
|
||||
@@ -26,3 +28,8 @@ export const actions = {
|
||||
throw redirect(303, ROUTE_NAMES.VORGANG(vorgangToken));
|
||||
}
|
||||
} as const;
|
||||
|
||||
export const load: PageServerLoad = async ({ url }) => {
|
||||
const vorgang = url.searchParams.get('vorgang');
|
||||
if (!vorgang) error(404, "Not Found");
|
||||
};
|
||||
Reference in New Issue
Block a user