-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
143 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# rename file to .env.local | ||
|
||
## Postgres | ||
CONNECTION_STRING='' | ||
|
||
## Google Auth | ||
GOOGLE_CLIENT_ID='' | ||
GOOGLE_CLIENT_SECRET='' | ||
REDIRECT_URI='' | ||
REDIRECT_URI='' | ||
|
||
## TURSO | ||
TURSO_CONNECTION_URL='' | ||
TURSO_AUTH_TOKEN='' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import type { Session, User } from "lucia"; | ||
|
||
// for debugging & simulating real-world delays | ||
export function sleep(ms: number) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
export function sessionExists(locals: App.Locals): locals is App.Locals & { session: Session, user: User } { | ||
return !!locals?.session?.id && !!locals?.user?.id | ||
} |
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,9 +1,10 @@ | ||
import { sessionExists } from "$lib/common.util.js"; | ||
import { ROUTES } from "$lib/routes.util.js"; | ||
import { redirect } from "@sveltejs/kit"; | ||
|
||
export async function load({ locals }) { | ||
console.log('auth') | ||
if (locals.user) { | ||
if (sessionExists(locals)) { | ||
redirect(302, ROUTES.HOME) | ||
} | ||
} |
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,9 +1,10 @@ | ||
import { sessionExists } from "$lib/common.util.js"; | ||
import { ROUTES } from "$lib/routes.util.js"; | ||
import { redirect } from "@sveltejs/kit"; | ||
|
||
export async function load({ locals }) { | ||
console.log('protected') | ||
if (!locals.user) { | ||
if (!sessionExists(locals)) { | ||
redirect(302, ROUTES.LOGIN) | ||
} | ||
} |
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,35 @@ | ||
import { sessionExists } from '$lib/common.util.js'; | ||
import { deleteCard, getCards } from '$lib/db/tables/card.table.js'; | ||
import { ROUTES } from '$lib/routes.util.js'; | ||
import { redirect } from '@sveltejs/kit'; | ||
|
||
export async function load({ locals }) { | ||
if (!sessionExists(locals)) { | ||
redirect(302, ROUTES.LOGIN) | ||
} | ||
const cards = await getCards(locals.user.id) | ||
return { cards }; | ||
} | ||
|
||
export const actions = { | ||
delete: async function ({ locals, request }) { | ||
const data = await request.formData(); | ||
const id = data.get('id') as string | ||
|
||
try { | ||
if (!sessionExists(locals)) { | ||
redirect(302, ROUTES.LOGIN); | ||
} | ||
if (!id) { | ||
return { status: 400, body: { message: 'No id provided' } }; | ||
} | ||
await deleteCard({ | ||
cardId: id, | ||
userId: locals.user.id, | ||
}); | ||
redirect(302, ROUTES.HOME); | ||
} catch (err) { | ||
console.error('delete ~ err:', err); | ||
} | ||
} | ||
} |
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,15 @@ | ||
<script lang="ts"> | ||
export let data; | ||
</script> | ||
|
||
{#each data.cards as card} | ||
<div class="border"> | ||
<div>{card.front}</div> | ||
<div>{card.back}</div> | ||
<form method="post" action="?/delete"> | ||
<input type="hidden" name="id" value={card.id} /> | ||
<button type="submit">Delete</button> | ||
</form> | ||
<hr /> | ||
</div> | ||
{/each} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { sessionExists } from "$lib/common.util.js"; | ||
import { ROUTES } from "$lib/routes.util.js"; | ||
import { redirect } from "@sveltejs/kit"; | ||
|
||
export async function load({ locals }) { | ||
if (locals.user) { | ||
if (sessionExists(locals)) { | ||
redirect(302, ROUTES.HOME) | ||
} | ||
} |
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