diff --git a/README.md b/README.md
index 5c91169..0e52582 100644
--- a/README.md
+++ b/README.md
@@ -36,3 +36,71 @@ npm run build
You can preview the production build with `npm run preview`.
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
+
+////////////////
+
+Right now, my signup page is set up like that:
+
+
+ Sign Up
+
+
+
+
+
+
@@ -49,6 +50,7 @@
align-items: center;
.modal-content {
font-size: 1.6rem;
+ padding: 30px;
}
}
button {
diff --git a/src/lib/api.js b/src/lib/api.js
index f8101fa..8ec2992 100644
--- a/src/lib/api.js
+++ b/src/lib/api.js
@@ -26,6 +26,7 @@ export async function login(email, password) {
headers: {
'Content-Type': 'application/json',
},
+ credentials: 'include',
body: JSON.stringify({
email: email,
password: password
@@ -38,6 +39,9 @@ export async function login(email, password) {
}
// Here you could do something with the login response, like storing a user token
-
+ //localStorage.setItem('userToken', data.token);
+ //cookie.set('userToken', data.token, { expires: 7 });
+ //cookie.set("check", "check", { expires: 7 })
+ console.log(data)
return data;
}
\ No newline at end of file
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index b41ac54..1673ddf 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -3,6 +3,7 @@
-
+
Welcome to SvelteKit
@@ -53,7 +55,7 @@
-
+
{#each notes as note}
@@ -63,4 +65,12 @@
Just to check, the current API endpoint is : {apiUrl}
-
\ No newline at end of file
+
+
+
\ No newline at end of file
diff --git a/src/routes/login/+page.server.js b/src/routes/login/+page.server.js
new file mode 100644
index 0000000..8ca37e8
--- /dev/null
+++ b/src/routes/login/+page.server.js
@@ -0,0 +1,48 @@
+import { redirect } from "@sveltejs/kit";
+import { login } from '$lib/api';
+
+export const load = async (event) => {
+ console.log("hello from backend")
+ const sessionID = event.cookies.get('sessionID');
+
+ if (sessionID) {
+ throw redirect('/profile');
+ }
+};
+
+export const actions = {
+ default: async (event) => {
+ const formData = await event.request.formData();
+ const email = formData.get('email');
+ const password = formData.get('password');
+
+
+ const apiUrl = import.meta.env.VITE_API_URL;
+
+ const res = await fetch(apiUrl + '/login', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ credentials: 'include',
+ body: JSON.stringify({
+ email: email,
+ password: password
+ })
+ });
+
+ if (res.ok) {
+ console.log("ok")
+ return redirect('/profile');
+ } else {
+ console.log("not ok")
+ const error = await res.json();
+ return {
+ status: 400,
+ redirect: '/login',
+ body: { error }
+ };
+ }
+
+ },
+};
\ No newline at end of file
diff --git a/src/routes/login/+page.svelte b/src/routes/login/+page.svelte
index 941493b..92e7979 100644
--- a/src/routes/login/+page.svelte
+++ b/src/routes/login/+page.svelte
@@ -4,27 +4,66 @@
+
+
-
-
\ No newline at end of file
+
+
+{#if showModal}
+
+
{modalMessage}
+
+{/if}
+
+
+
\ No newline at end of file
diff --git a/src/routes/profile/+page.svelte b/src/routes/profile/+page.svelte
new file mode 100644
index 0000000..fa48c8d
--- /dev/null
+++ b/src/routes/profile/+page.svelte
@@ -0,0 +1,22 @@
+
+
+
Profile
+
\ No newline at end of file
diff --git a/src/routes/signup/+page.svelte b/src/routes/signup/+page.svelte
index d46c6e5..e9e9a2c 100644
--- a/src/routes/signup/+page.svelte
+++ b/src/routes/signup/+page.svelte
@@ -6,34 +6,49 @@
import { signup } from '$lib/api';
import { isValidEmail, isValidPassword } from '$lib/utils';
import Modal from '$components/Modal.svelte';
+ import Header from '$components/Header.svelte';
+ import Footer from '$components/Footer.svelte';
+ import { navigate } from 'svelte-navigator';
- let showModal = true;
+ let showModal = false;
let modalMessage = 'Test message';
let email = '';
let password = '';
async function handleSignup() {
+ if (!isValidEmail(email)){
+ modalMessage = 'This: "'+ email +'" does not look like a valid email address. Imagine you lose your password, how would you get it back? We need to send you an email. Without a valid email address, that will be difficult.';
+ showModal = true;
+ return;
+ }
+ if (!isValidPassword(password)){
+ modalMessage = 'My bad, I thought the UI was clear. Password must be at least 8 characters long with at least one number, one lowercase letter, one uppercase letter and one special character (try again until the line is no longer red, you silly goose)';
+ showModal = true;
+ return;
+ }
try {
const user = await signup(email, password);
- alert('Signup successful');
+ sessionStorage.setItem('formSubmitted', 'true');
+ navigate('/signup/success');
} catch (err) {
- alert('Signup failed because of : ' + err);
+ modalMessage = err;
+ showModal = true;
}
}
- async function handleSubmit(event) {
- event.preventDefault(); // prevent the form from refreshing the page
- await handleSignup();
- }
-
+
function closeModal() {
showModal = false;
}
+ let showUserNav = false;
+
+
+
-
{#if showModal}
-
+
+
{modalMessage}
+
{/if}
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/src/routes/signup/success/+page.svelte b/src/routes/signup/success/+page.svelte
new file mode 100644
index 0000000..4cab2a9
--- /dev/null
+++ b/src/routes/signup/success/+page.svelte
@@ -0,0 +1,33 @@
+
+
+ {#if formSubmitted}
+
+
+
+
Signup successful!
+
You can now check your inbox to activate your account.