-
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.
Register and login (50%) is working. Need to patch cookies.
- Loading branch information
1 parent
ec65f59
commit 0080ab6
Showing
13 changed files
with
1,253 additions
and
1,083 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,17 +1,17 @@ | ||
{ | ||
"name": "client", | ||
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
"dev": "vite dev", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
}, | ||
"devDependencies": { | ||
"@sveltejs/adapter-auto": "^2.0.0", | ||
"@sveltejs/kit": "^1.27.4", | ||
"svelte": "^4.0.5", | ||
"vite": "^4.4.2" | ||
}, | ||
"type": "module" | ||
"name": "client", | ||
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
"dev": "vite dev", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
}, | ||
"devDependencies": { | ||
"@sveltejs/adapter-auto": "^2.0.0", | ||
"@sveltejs/kit": "^1.27.4", | ||
"svelte": "^4.0.5", | ||
"vite": "^4.4.2" | ||
}, | ||
"type": "module" | ||
} |
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,5 @@ | ||
<h1>Welcome to Local Bargains</h1> | ||
<a href="/auth/register"> Sign up </a> | ||
<a href="/auth/login"> Sign in </a> | ||
|
||
<slot /> |
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,6 @@ | ||
export function load({ cookies }) { | ||
const accessToken = cookies.get('accessToken'); | ||
return { | ||
accessToken | ||
}; | ||
} |
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,2 +1,7 @@ | ||
<h1>Welcome to SvelteKit</h1> | ||
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p> | ||
<script> | ||
</script> | ||
|
||
<svelte:head> | ||
<title>Local Bargains!</title> | ||
</svelte:head> | ||
<p>Hello</p> |
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,41 @@ | ||
import { fail, redirect } from '@sveltejs/kit'; | ||
|
||
export const actions = { | ||
form: async ({ request, url, cookies }) => { | ||
const data = await request.formData(); | ||
const email = data.get('email').trim(); | ||
const password = data.get('password').trim(); | ||
|
||
if (!email || !password) { | ||
return fail(400, { | ||
email, | ||
message: 'Missing username or password!' | ||
}); | ||
} | ||
const reqBody = new URLSearchParams(); | ||
reqBody.append("email", email); | ||
reqBody.append("password", password); | ||
const response = await fetch("http://localhost:3000/api/auth/login", { | ||
method: "post", | ||
mode: "no-cors", | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
body: reqBody, | ||
}); | ||
if (response.status === 418) { | ||
return fail(400, { | ||
email, | ||
message: 'Bad email!' | ||
}); | ||
} else if (response.status === 401) { | ||
return fail(400, { | ||
email, | ||
message: 'Bad password!' | ||
}); | ||
} | ||
console.log(response); | ||
console.log(cookies.getAll()); | ||
throw redirect(303, url.searchParams.get('redirectTo') || '/'); | ||
} | ||
} |
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,24 @@ | ||
<script> | ||
import { page } from "$app/stores"; | ||
export let form; | ||
const redirectTo = $page.url.searchParams.get("redirectTo") || "/"; | ||
</script> | ||
|
||
<svelte:head> | ||
<title>Local Bargains! - Login</title> | ||
</svelte:head> | ||
|
||
<h1>Sign in!</h1> | ||
<form method="post"> | ||
<p>{form?.message || ""}</p> | ||
<input | ||
type="text" | ||
name="email" | ||
placeholder="Email" | ||
value={form?.email ?? ""} | ||
/> | ||
<input type="password" name="password" placeholder="Password" /> | ||
<button type="submit" formaction="?/form&redirectTo={redirectTo}"> | ||
Login | ||
</button> | ||
</form> |
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,42 @@ | ||
import { fail, redirect } from '@sveltejs/kit'; | ||
|
||
export const actions = { | ||
form: async ({ request, url }) => { | ||
const data = await request.formData(); | ||
const username = data.get('username').trim(); | ||
const email = data.get('email').trim(); | ||
const password = data.get('password').trim(); | ||
|
||
if (!email || !password || !username) { | ||
return fail(400, { | ||
email, | ||
message: 'Missing username, email or password!' | ||
}); | ||
} | ||
const reqBody = new URLSearchParams(); | ||
reqBody.append("username", username); | ||
reqBody.append("email", email); | ||
reqBody.append("password", password); | ||
const response = await fetch("http://localhost:3000/api/auth/register", { | ||
method: "post", | ||
mode: "no-cors", | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
body: reqBody, | ||
}); | ||
if (response.status === 418) { | ||
return fail(400, { | ||
email, | ||
message: 'Bad email!' | ||
}); | ||
} else if (response.status === 401) { | ||
return fail(400, { | ||
email, | ||
message: 'Bad password!' | ||
}); | ||
} | ||
|
||
throw redirect(303, url.searchParams.get('redirectTo') || '/'); | ||
} | ||
} |
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,30 @@ | ||
<script> | ||
import { page } from "$app/stores"; | ||
export let form; | ||
const redirectTo = $page.url.searchParams.get("redirectTo") || "/"; | ||
</script> | ||
|
||
<svelte:head> | ||
<title>Local Bargains! - Register</title> | ||
</svelte:head> | ||
|
||
<h1>Sign up!</h1> | ||
<form method="post"> | ||
<p>{form?.message || ""}</p> | ||
<input | ||
type="username" | ||
name="username" | ||
placeholder="Username" | ||
value={form?.username ?? ""} | ||
/> | ||
<input | ||
type="text" | ||
name="email" | ||
placeholder="Email" | ||
value={form?.email ?? ""} | ||
/> | ||
<input type="password" name="password" placeholder="Password" /> | ||
<button type="submit" formaction="?/form&redirectTo={redirectTo}"> | ||
Register | ||
</button> | ||
</form> |
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,13 +1,16 @@ | ||
import adapter from '@sveltejs/adapter-auto'; | ||
import { vitePreprocess } from "@sveltejs/kit/vite"; | ||
import adapter from "@sveltejs/adapter-auto"; | ||
|
||
/** @type {import('@sveltejs/kit').Config} */ | ||
const config = { | ||
kit: { | ||
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list. | ||
// If your environment is not supported or you settled on a specific environment, switch out the adapter. | ||
// See https://kit.svelte.dev/docs/adapters for more information about adapters. | ||
adapter: adapter() | ||
} | ||
kit: { | ||
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list. | ||
// If your environment is not supported or you settled on a specific environment, switch out the adapter. | ||
// See https://kit.svelte.dev/docs/adapters for more information about adapters. | ||
adapter: adapter(), | ||
}, | ||
|
||
preprocess: [vitePreprocess({})], | ||
}; | ||
|
||
export default config; |
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