Hi! I've been trying to get the "remember me" func...
# help
f
Hi! I've been trying to get the "remember me" functionality for my site working and I'm having trouble with the access/refresh token setup. So, let's say I have a navigation guard for some routes (like
/user/profile
) and want to check if the current user is authenticated:
Copy code
js
async function isAuthenticated() {
   // User has session?
   if(supabase.auth.session == null) {
      // We don't, check if there's an old session in storage (local/session Storage)
      const oldSession = getStorageSession();
      // Has it expired yet?
      if (oldSession.expiresAt >= Date.now()) {
        loginWithRefreshToken(); 
        return true;
      }
      else {
        // setAuth with old session (does Supabase handle this automatically?)
        await supabase.auth.setAuth(oldSession.access_token);
        return true;
      }
   }
   else {
    // We have a session, is it expired though?
    if(supabase.auth.session.expiresAt >= Date.now() {
      loginWithRefreshToken();
      return true;
    }
   }
  // On error logging in with refresh token, returns false.
}
However, I receive "Invalid access token" after trying to login with the refresh token... Is there any step I'm missing, or is there any misunderstandings with how I should handle authentication with Supabase Auth?
n
Hello @fmontanari! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
🆕 Refresh Token login not working?