-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/jetlog-import
- Loading branch information
Showing
20 changed files
with
336 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,12 @@ | ||
import type { Actions, PageServerLoad } from './$types'; | ||
import type { PageServerLoad } from './$types'; | ||
import { trpcServer } from '$lib/server/server'; | ||
import { message, superValidate } from 'sveltekit-superforms'; | ||
import { superValidate } from 'sveltekit-superforms'; | ||
import { zod } from 'sveltekit-superforms/adapters'; | ||
import { signInSchema } from '$lib/zod/auth'; | ||
import { createSession, getUser } from '$lib/server/utils/auth'; | ||
import { lucia } from '$lib/server/auth'; | ||
import { fail, redirect } from '@sveltejs/kit'; | ||
import { verifyPassword } from '$lib/server/utils/password'; | ||
|
||
export const load: PageServerLoad = async (event) => { | ||
await trpcServer.user.isSetup.ssr(event); | ||
|
||
const form = await superValidate(zod(signInSchema)); | ||
return { form }; | ||
}; | ||
|
||
export const actions: Actions = { | ||
default: async (event) => { | ||
const form = await superValidate(event, zod(signInSchema)); | ||
if (!form.valid) { | ||
return fail(400, { form }); | ||
} | ||
|
||
const { username, password } = form.data; | ||
|
||
const user = await getUser(username); | ||
if (!user) { | ||
return message( | ||
form, | ||
{ type: 'error', text: 'Invalid username or password' }, | ||
{ status: 403 }, | ||
); | ||
} | ||
|
||
const validPassword = await verifyPassword(user.password, password); | ||
if (!validPassword) { | ||
return message( | ||
form, | ||
{ type: 'error', text: 'Invalid username or password' }, | ||
{ status: 403 }, | ||
); | ||
} | ||
|
||
await createSession(lucia, user.id, event.cookies); | ||
|
||
redirect(302, '/'); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,12 @@ | ||
import type { Actions, PageServerLoad } from './$types'; | ||
import type { PageServerLoad } from './$types'; | ||
import { trpcServer } from '$lib/server/server'; | ||
import { message, setError, superValidate } from 'sveltekit-superforms'; | ||
import { superValidate } from 'sveltekit-superforms'; | ||
import { zod } from 'sveltekit-superforms/adapters'; | ||
import { signUpSchema } from '$lib/zod/auth'; | ||
import { fail, redirect } from '@sveltejs/kit'; | ||
import { | ||
createSession, | ||
createUser, | ||
usernameExists, | ||
} from '$lib/server/utils/auth'; | ||
import { generateId } from 'lucia'; | ||
import { lucia } from '$lib/server/auth'; | ||
import { hashPassword } from '$lib/server/utils/password'; | ||
|
||
export const load: PageServerLoad = async (event) => { | ||
await trpcServer.user.isSetup.ssr(event); | ||
|
||
const form = await superValidate(zod(signUpSchema)); | ||
return { form }; | ||
}; | ||
|
||
export const actions: Actions = { | ||
default: async (event) => { | ||
const form = await superValidate(event, zod(signUpSchema)); | ||
if (!form.valid) { | ||
return fail(400, { form }); | ||
} | ||
|
||
const { username, password, displayName, unit } = form.data; | ||
const exists = await usernameExists(username); | ||
if (exists) { | ||
return setError(form, 'username', 'Username already exists'); | ||
} | ||
|
||
const userId = generateId(15); | ||
const hashedPassword = await hashPassword(password); | ||
|
||
// Always create the first user as the owner | ||
const success = await createUser( | ||
userId, | ||
username, | ||
hashedPassword, | ||
displayName, | ||
unit, | ||
'owner', | ||
); | ||
|
||
if (!success) { | ||
return message(form, { type: 'error', text: 'Failed to create user' }); | ||
} | ||
|
||
await createSession(lucia, userId, event.cookies); | ||
|
||
return redirect(302, '/'); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<script lang="ts"> | ||
import { page } from '$app/stores'; | ||
import { Button } from '$lib/components/ui/button'; | ||
</script> | ||
|
||
<div class="flex flex-col h-full items-center justify-center"> | ||
{#if $page.status === 404} | ||
<h1 class="text-3xl font-bold">404</h1> | ||
<p class="text-lg">Page not found</p> | ||
<Button href="/" variant="outline">Go back</Button> | ||
{:else} | ||
<h1 class="text-4xl font-bold">An unknown error occured</h1> | ||
<p class="text-lg">{$page.error?.message}</p> | ||
<p class="italic text-sm"> | ||
If you are the site owner, please check the logs for more information. | ||
</p> | ||
{/if} | ||
</div> |
Oops, something went wrong.