Lucia Authentication #8
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 { logger } from '$lib/server/logger';
|
||||||
import { prisma } from '$lib/server/prisma';
|
import { prisma } from '$lib/server/prisma';
|
||||||
import { error, redirect, type Actions } from '@sveltejs/kit';
|
import { error, redirect, type Actions } from '@sveltejs/kit';
|
||||||
//import { password } from 'bun';
|
|
||||||
import { Argon2id } from "oslo/password"
|
import { Argon2id } from "oslo/password"
|
||||||
import { generateId } from 'lucia';
|
|
||||||
import { auth } from '$lib/server/lucia.js';
|
import { auth } from '$lib/server/lucia.js';
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
|
|
@ -21,12 +19,25 @@ export const actions = {
|
||||||
logger.error('User not found! ${user}');
|
logger.error('User not found! ${user}');
|
||||||
return error(401);
|
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: '/',
|
path: '/',
|
||||||
maxAge: 120
|
maxAge: 120
|
||||||
});
|
});
|
||||||
redirect(302, '/');
|
redirect(302, '/');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
register: async (event) => {
|
register: async (event) => {
|
||||||
const form = await event.request.formData();
|
const form = await event.request.formData();
|
||||||
if (!form.has('email') || !form.has('name') || !form.has('password')) {
|
if (!form.has('email') || !form.has('name') || !form.has('password')) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue