From 16d8b61ccf90ad40e72249abd2e35dfdce0b1fbc Mon Sep 17 00:00:00 2001 From: silvestrevivo Date: Mon, 11 May 2020 22:51:06 +0200 Subject: [PATCH 1/2] token available in client --- src/components/Nav.svelte | 186 +++++++++++++------- src/node_modules/api.js | 4 +- src/routes/auth/login.js | 2 +- src/routes/login/index.svelte | 293 +++++++++++++++---------------- src/routes/projects/index.svelte | 128 +++++++------- 5 files changed, 330 insertions(+), 283 deletions(-) diff --git a/src/components/Nav.svelte b/src/components/Nav.svelte index 5d83e0f..7eedfc2 100644 --- a/src/components/Nav.svelte +++ b/src/components/Nav.svelte @@ -1,80 +1,136 @@ diff --git a/src/node_modules/api.js b/src/node_modules/api.js index 42392ce..1cb3cf8 100644 --- a/src/node_modules/api.js +++ b/src/node_modules/api.js @@ -1,4 +1,4 @@ -const base = 'http://localhost:5000/api/v1'; +const base = 'http://localhost:3000/api/v1'; function send({ method, path, data, token }) { @@ -12,7 +12,7 @@ function send({ method, path, data, token }) { } if (token) { - opts.headers['Authorization'] = `Token ${token}`; + opts.headers['Authorization'] = `Bearer ${token}`; } return fetch(`${base}/${path}`, opts) diff --git a/src/routes/auth/login.js b/src/routes/auth/login.js index 5068614..2320c9d 100644 --- a/src/routes/auth/login.js +++ b/src/routes/auth/login.js @@ -4,7 +4,7 @@ export function post(req, res) { const user = req.body; api.post('auth/login', user ).then(response => { - if (response.user) req.session.user = response.user; + if (response.user) req.session.user = response.user; req.session.token = response.token; res.end(JSON.stringify(response)); }); } diff --git a/src/routes/login/index.svelte b/src/routes/login/index.svelte index 0eab319..d433f30 100644 --- a/src/routes/login/index.svelte +++ b/src/routes/login/index.svelte @@ -1,170 +1,167 @@ -
+ +
-
-
- -

Sign in to continue to Plateform.

+
+
+ +

Sign in to continue to Plateform.

+
+
+
+ (email = event.target.value)} /> +
+
+ (password = event.target.value)} /> +
+
+
+
- -
- (email = event.target.value)} - /> -
-
- (password = event.target.value)} - /> -
-
-
- -
-
- -
-
- - + + -
\ No newline at end of file +
+
diff --git a/src/routes/projects/index.svelte b/src/routes/projects/index.svelte index b63165c..9698b0d 100644 --- a/src/routes/projects/index.svelte +++ b/src/routes/projects/index.svelte @@ -1,82 +1,77 @@
-

Your Plateform Projects

- settings +

Your Plateform Projects

+ settings

Projects

-
{JSON.stringify($projects, null, 2)}
+
{JSON.stringify(projects, null, 2)}
- \ No newline at end of file +{/each} --> From 419961b3c1b389d6701f1c058983353036e62570 Mon Sep 17 00:00:00 2001 From: silvestrevivo Date: Tue, 12 May 2020 09:07:32 +0200 Subject: [PATCH 2/2] links on navigation changing with session --- src/components/Nav.svelte | 2 ++ src/routes/login/index.svelte | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/Nav.svelte b/src/components/Nav.svelte index 7eedfc2..2829830 100644 --- a/src/components/Nav.svelte +++ b/src/components/Nav.svelte @@ -119,6 +119,8 @@ aria-current={segment === 'projects' ? 'page' : undefined} href="projects" rel="prefetch"> + Projects diff --git a/src/routes/login/index.svelte b/src/routes/login/index.svelte index d433f30..b82a584 100644 --- a/src/routes/login/index.svelte +++ b/src/routes/login/index.svelte @@ -31,12 +31,17 @@ } if (response.user) { - //! I think this is doing nothing!!! - // $session.user = response.user; - // $session.token = response.token; + $session.user = response.user; goto("/dashboard"); } } + + // Another suggestion. If the routes don't have a subroute, don't create a folder + // with the name and then create a index.svelte File. That is not a very good + // practive with Svelte + + // other thing, register.svelte is not on route and that refresh the page enterily. Place + // that file inside the route folder