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

@@ -0,0 +1,38 @@
<script lang="ts">
import { fly, fade } from "svelte/transition";
import { goto } from "$app/navigation";
import { pageWidth } from "$lib/stores";
import type { LayoutServerData } from "../$types.js";
export let data: LayoutServerData
const contentTabs = {
'/': {
header: 'Home',
icon: 'fa-solid fa-house',
},
'/account': {
header: data.user.username,
icon: 'fa-solid fa-user',
},
'/search': {
header: 'Search',
icon: 'fa-solid fa-search',
},
'/library': {
header: 'Libray',
icon: 'fa-solid fa-bars-staggered',
},
}
const pageTransitionTime: number = 200
let previousPage = data.urlPathname
type PageTransitionDirection = 1 | -1
let direction: PageTransitionDirection = 1
const calculateDirection = (newPage: string): void => {
const contentLinks = Object.keys(contentTabs)
const newPageIndex = contentLinks.indexOf(newPage)
}
</script>

View File

@@ -0,0 +1,5 @@
import type { LayoutServerLoad } from './$types'
export const load: LayoutServerLoad = ({ url, locals }) => {
return { urlPathname: url.pathname, user: locals.user }
}

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 })