-
Hi, I'm playing around with authentication with Remix and ran into a bit of a problem with Firebase authentication. My setup is that when a user signs in with Firebase, I'll create a new cookie session storage with the Everything works great except for the case when a user comes back to an authenticated route after their token has expired. Because the idToken is expired, the route will throw a 401 error. As the FE code rehydrates, Firebase will fetch a new idToken and update the cookie. However, the users will still need to refresh the page for everything to work correctly. Currently, I have an effect in the useEffect(() => {
if (typeof window === "undefined") return;
if (caught.status !== 401) return;
if (caught.data?.type !== "expired_token") return;
const timeout = setTimeout(() => window.location.reload(), 1000);
return () => clearTimeout(timeout);
}, [caught]); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hey, I think the solution here is to use "the remix approach". Firebase by default handles authentication, tokens and the like on the client. Usually you would handle sessions and cookies on the server. Which is why remix provides elegant tooling for this. The approach is the following:
This cookie can live up to two weeks, which should be enough. Verify the token from the cookie using the |
Beta Was this translation helpful? Give feedback.
Hey, I think the solution here is to use "the remix approach".
Firebase by default handles authentication, tokens and the like on the client. Usually you would handle sessions and cookies on the server. Which is why remix provides elegant tooling for this.
The approach is the following:
signInWithEmailAndPassword
in your server. Yes, its the client-sdk we will use here.