Moderator
then use account.get but wrap it in a try/catch
Votes
0
Replies
24
Participants
Unknown
Messages
25
Moderator
then use account.get but wrap it in a try/catch
Moderator
so for instance
Moderator
const isLoggedIn = computed(() => { const maybeLocal = localStorage.getItem("pvauser"); if (maybeLocal) { $user.value = JSON.parse(maybeLocal); return true; } else if ($user.value) { return true; } else { return false; } });Moderator
that's a basic computed to check my store value
Moderator
What I would recommend is something like
Moderator
const isLoggedIn = async () => { try { const user = await account.get(); return user (or true); catch (e) { return null | undefined; }}Moderator
For a user to register, you simply have to do account.create(ID, email, password)
Rank 1: Thread
Yea my getUser function is defined like this only
Moderator
perfect
Moderator
then when they login
Moderator
you want to do account.createEmailSession
Moderator
That is what creates the session
Moderator
that account.get() looks for
Moderator
if that session exists, then it won't error and will return the user
Rank 1: Thread
Ah oke i just don't want the error to show in console, so it doesn't show to the user, but if it won't crash the app I think it's no harm
Moderator
If you use try/catch
Moderator
it won't error in the console
Moderator
I know what you mean, I thought the same exact thing haha
Moderator
but try/catch is easy and consistent
Moderator
and it works for most so like
Moderator
getDocument
Moderator
will error if there is no document
Rank 1: Thread
Defined all these functions in the auth_service file so I think I am going on the right path I just need to recheck the try/catch as u said
Moderator
yeah let me know if you need any more help 🙂
Rank 1: Thread
Sure and thanks for the help guys