lucia login done
This commit is contained in:
parent
a6c6b4a7a7
commit
905505c1b6
2 changed files with 14 additions and 3 deletions
BIN
prisma/dev.db
BIN
prisma/dev.db
Binary file not shown.
|
|
@ -1,9 +1,7 @@
|
|||
import { logger } from '$lib/server/logger';
|
||||
import { prisma } from '$lib/server/prisma';
|
||||
import { error, redirect, type Actions } from '@sveltejs/kit';
|
||||
//import { password } from 'bun';
|
||||
import { Argon2id } from "oslo/password"
|
||||
import { generateId } from 'lucia';
|
||||
import { auth } from '$lib/server/lucia.js';
|
||||
|
||||
export const actions = {
|
||||
|
|
@ -21,12 +19,25 @@ export const actions = {
|
|||
logger.error('User not found! ${user}');
|
||||
return error(401);
|
||||
}
|
||||
event.cookies.set('user', String(user.id), {
|
||||
const pw = form.get('password') as string;
|
||||
if(!pw) {
|
||||
return error(401, 'Password is required')
|
||||
}
|
||||
const validPassword = await new Argon2id().verify(user.password,pw);
|
||||
if(!validPassword) {
|
||||
return error(400, 'Password is incorrect!');
|
||||
}
|
||||
const session = await auth.createSession(user.id, []);
|
||||
const sessionCookie = auth.createSessionCookie(session.id);
|
||||
event.cookies.set(sessionCookie.name, sessionCookie.value, {
|
||||
path: '/',
|
||||
maxAge: 120
|
||||
});
|
||||
redirect(302, '/');
|
||||
},
|
||||
|
||||
|
||||
|
||||
register: async (event) => {
|
||||
const form = await event.request.formData();
|
||||
if (!form.has('email') || !form.has('name') || !form.has('password')) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue