Open MTyson opened 3 years ago
session.token.undefined
in your Nav.svelte
is undefined
. Try session.token.username
.
session.token.undefined
in yourNav.svelte
isundefined
. Trysession.token.username
.
Sorry, that was a typo. Fixed.
Another piece of info: If I reload the page (after login) the usename field then displays properly:
${"_id":"kjbLgeU8k3GPr6jBd8NkCj","username":"matt123","password":"$2b$10$aXMJc64o9W166OL12CG/A.lWyuB9zdPkaNUsze3Lch6Z2khHaTKY.","access":"user"} - $"matt123"
I use setTimeout(() => location.replace("/"), 1500);
to reload the page for me to prevent this issue.
Thanks @mikeoptics .
It's strange, if I use window.location.href
, it works ok, but if I use goto()
it has this problem.
Can you try await goto("/");
?
As mentioned in the Docs of Sapper, goto() returns a Promise that resolves when the navigation is complete.
Link - https://sapper.svelte.dev/docs#goto_href_options
P.S - awaiting goto() worked for me!
Ah, I will give await a try, thanks @Vaibhav-Kulkarni-4 !
In my nav.svelte component I have:
In login.svelte:
login.js handler:
server.js:
The output in nav.svelte is:
${"token":{"_id":"kjbLgeU8k3GPr6jBd8NkCj","username":"matt123","password":"$2b$10$aXMJc64o9W166OL12CG/A.lWyuB9zdPkaNUsze3Lch6Z2khHaTKY.","access":"user"}} - $undefined
Notice that the data is there, but username outputs undefined. I believe I am doing something wrong but it is obscure.