-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from NickRTR/database
Authentication system
- Loading branch information
Showing
22 changed files
with
1,768 additions
and
374 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
{ | ||
"name": "syntype", | ||
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
"dev": "vite dev", | ||
"build": "vite build", | ||
"package": "svelte-kit package", | ||
"preview": "vite preview", | ||
"prepare": "svelte-kit sync", | ||
"lint": "prettier --check --plugin-search-dir=. .", | ||
"format": "prettier --write --plugin-search-dir=. ." | ||
"lint": "prettier --check .", | ||
"format": "prettier --write ." | ||
}, | ||
"devDependencies": { | ||
"@sveltejs/adapter-auto": "next", | ||
"@sveltejs/kit": "next", | ||
"prettier": "^2.6.2", | ||
"prettier-plugin-svelte": "^2.7.0", | ||
"svelte": "^3.44.0", | ||
"vite": "^3.0.0" | ||
"vite": "^3.1.0-beta.1", | ||
"@supabase/supabase-js": "^1.35.4" | ||
}, | ||
"type": "module", | ||
"dependencies": { | ||
"cookie": "^0.5.0", | ||
"dotenv": "^16.0.1", | ||
"svelte-local-storage-store": "^0.2.6" | ||
} | ||
} |
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import dotenv from "dotenv"; | ||
import { createClient } from "@supabase/supabase-js"; | ||
|
||
dotenv.config(); | ||
|
||
export const supabase = createClient(process.env["SUPABASE_URL"], process.env["SUPABASE_KEY"]); | ||
|
||
export default supabase; |
File renamed without changes.
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,8 @@ | ||
import { redirect } from "@sveltejs/kit"; | ||
|
||
export async function load({ parent }) { | ||
const { desktop } = await parent(); | ||
if (desktop === true) { | ||
throw redirect(302, "/"); | ||
} | ||
} |
File renamed without changes.
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,26 @@ | ||
import { parse } from "cookie"; | ||
import supabase from "$lib/supabase"; | ||
|
||
export async function load({ request }) { | ||
const userAgent = request.headers.get("user-agent"); | ||
const desktop = !/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent); | ||
|
||
const cookieString = request.headers.get("cookie"); | ||
if (cookieString !== null) { | ||
const cookies = parse(request.headers.get("cookie")); | ||
if (cookies.auth) { | ||
const user = await supabase.auth.api.getUser(cookies.auth); | ||
return { | ||
user: { | ||
email: user.user.email, | ||
id: user.user.id | ||
}, | ||
desktop | ||
}; | ||
} | ||
|
||
return { | ||
desktop | ||
}; | ||
} | ||
} |
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,8 @@ | ||
import { redirect } from "@sveltejs/kit"; | ||
|
||
export async function load({ parent }) { | ||
const { desktop } = await parent(); | ||
if (desktop === false) { | ||
throw redirect(302, "/mobile"); | ||
} | ||
} |
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,12 @@ | ||
import { redirect } from "@sveltejs/kit"; | ||
|
||
export async function load({ parent }) { | ||
const { user } = await parent(); | ||
if (!user) { | ||
throw redirect(307, "/account/login"); | ||
} | ||
|
||
return { | ||
user | ||
}; | ||
} |
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,8 @@ | ||
<script> | ||
export let data; | ||
</script> | ||
|
||
<body> | ||
<h1>Dashboard</h1> | ||
<p>Hello {data.user.email}</p> | ||
</body> |
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,8 @@ | ||
import { redirect } from "@sveltejs/kit"; | ||
|
||
export async function load({ parent }) { | ||
const { user } = await parent(); | ||
if (user) { | ||
throw redirect(307, "/account"); | ||
} | ||
} |
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,20 @@ | ||
import { redirect } from "@sveltejs/kit"; | ||
import supabase from "$lib/supabase"; | ||
|
||
export async function POST({ request }) { | ||
const form = await request.formData(); | ||
const email = form.get("email"); | ||
|
||
const response = await supabase.auth.signIn({ email }); | ||
|
||
if (response.error) { | ||
return { | ||
status: response.error.status, | ||
errors: { | ||
message: response.error.message | ||
} | ||
}; | ||
} | ||
|
||
throw redirect(307, "/account"); | ||
} |
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,102 @@ | ||
<script> | ||
let error; | ||
let success; | ||
// this runs on the client when JavaScript is available | ||
// so we can just reuse the existing `error` and `success` props | ||
async function login(event) { | ||
// reset error and success messages | ||
error = undefined; | ||
success = undefined; | ||
const form = event.target; | ||
const res = await fetch(form.action, { | ||
method: form.method, | ||
body: new FormData(form), | ||
headers: { accept: "application/json" } | ||
}); | ||
let response = await res.json(); | ||
if (response.errors) { | ||
error = response.errors.message; | ||
} else { | ||
} | ||
form.reset(); | ||
} | ||
</script> | ||
|
||
<body> | ||
<h1>Login / Signup</h1> | ||
|
||
<p id="description">Enter your email address to login or signup. You will then receive an email, maybe tagged as spam, with a confirmation link.</p> | ||
|
||
<form on:submit|preventDefault={login} method="post" autocomplete="off"> | ||
<div> | ||
<input id="email" name="email" placeholder="email" type="email" required /> | ||
</div> | ||
|
||
<button type="submit">Login</button> | ||
{#if error} | ||
<p class="error">Error: {error}</p> | ||
{/if} | ||
|
||
{#if success} | ||
<p class="success">{success}</p> | ||
{/if} | ||
</form> | ||
</body> | ||
|
||
<style> | ||
body { | ||
max-width: 400px; | ||
margin-inline: auto; | ||
} | ||
#description { | ||
margin-block: 0; | ||
} | ||
input { | ||
border-radius: 0.7rem; | ||
border: 2px solid var(--text); | ||
padding: 0.2rem 0.25rem; | ||
outline: none; | ||
transition: border 0.1s ease-in-out; | ||
font-size: 0.95rem; | ||
margin-block: 0.75rem; | ||
} | ||
input:hover, | ||
input:focus { | ||
border-color: var(--accent); | ||
} | ||
button { | ||
font-size: 1rem; | ||
font-weight: bold; | ||
background-color: var(--accent); | ||
border-radius: 1rem; | ||
padding: 0.6rem 1.1rem; | ||
outline: none; | ||
border: none; | ||
box-shadow: none; | ||
transition: box-shadow 0.1s ease-in-out; | ||
user-select: none; | ||
} | ||
button:hover, | ||
button:focus { | ||
box-shadow: 1px 1px 5px white; | ||
} | ||
.error { | ||
color: tomato; | ||
margin-block: 0.5rem; | ||
} | ||
.success { | ||
color: lime; | ||
margin-block: 0.5rem; | ||
} | ||
</style> |
Oops, something went wrong.
5e4efed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
syntype – ./
syntype-git-main-nickrtr.vercel.app
syntype.vercel.app
syntype-nickrtr.vercel.app