started refactoring (app) layout

This commit is contained in:
Eclypsed
2024-01-25 19:50:26 -05:00
parent 0ad1ace45b
commit 4fcfdc0ee6
7 changed files with 82 additions and 10 deletions

View File

@@ -3,7 +3,7 @@ import { fail, redirect } from '@sveltejs/kit'
import { compare, hash } from 'bcrypt-ts'
import type { PageServerLoad, Actions } from './$types'
import { Users } from '$lib/server/users'
import { sign } from 'jsonwebtoken'
import jwt from 'jsonwebtoken'
export const load: PageServerLoad = async ({ url }) => {
const redirectLocation = url.searchParams.get('redirect')
@@ -21,7 +21,7 @@ export const actions: Actions = {
const passwordValid = await compare(password.toString(), user.password!)
if (!passwordValid) return fail(400, { message: 'Invalid Password' })
const authToken = sign({ id: user.id, username: user.username }, SECRET_JWT_KEY, { expiresIn: '100d' })
const authToken = jwt.sign({ id: user.id, username: user.username }, SECRET_JWT_KEY, { expiresIn: '100d' })
cookies.set('lazuli-auth', authToken, { path: '/', httpOnly: true, sameSite: 'strict', secure: false, maxAge: 60 * 60 * 24 * 100 })
@@ -40,7 +40,7 @@ export const actions: Actions = {
const passwordHash = await hash(password.toString(), 10)
const newUser = Users.addUser(username.toString(), passwordHash)
const authToken = sign({ id: newUser.id, username: newUser.username }, SECRET_JWT_KEY, { expiresIn: '100d' })
const authToken = jwt.sign(newUser, SECRET_JWT_KEY, { expiresIn: '100d' })
cookies.set('lazuli-auth', authToken, { path: '/', httpOnly: true, sameSite: 'strict', secure: false, maxAge: 60 * 60 * 24 * 100 })