Using with Firebase Auth #279
-
Hello everyone 👋 First of all thank you to all contributers for this awesome library. I would like to ask some questions about authentication with firebase/auth in combination with remix-auth package as I am really confused. So I am using Email/Password login from firebase/auth and in my // auth.server.ts
authenticator.use(
new FormStrategy<User>(async ({ form }) => {
const email = String(form.get("email")).trim();
const password = String(form.get("password")).trim();
if (!email || email?.length === 0)
throw new AuthorizationError("Invalid Email");
if (!password || password?.length === 0)
throw new AuthorizationError("Invalid Password");
try {
const res = await signInWithEmailAndPassword(auth, email, password);
... // session.server.ts
export const sessionStorage = createCookieSessionStorage({
cookie: {
name: "_session",
sameSite: "lax",
path: "/",
httpOnly: true,
secrets: [`${process.env.AUTH_SECRET}`],
secure: process.env.NODE_ENV === "production",
maxAge: 60 * 60 * 24 * 7 // 7 Days
},
}); So far it seems fine, however the problem starts when I try to use the token in I am sure I am missing something or doing something wrong but I cannot wrap my head around it. Am I supposed to use different strategy other than Thanks 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Firebase should be giving you a refresh token that you can use to get a new access token, although an access token that expires in an hour is ok for a SPA/native app but not for an app like Remix where the token is stored securely in a cookie and accessed only server-side, if you could configure Firebase to never expire or give you larger expiration times would helps you a lot. |
Beta Was this translation helpful? Give feedback.
-
Alright, so after reading article by @sergiodxa and another one I found, I was able to have it working properly. Basically what I am doing is once user sign in/sign up I create a session cookie in Then in loder function of my protected routes first I check if user is authenticated (has session cookie in browser) with The reason I am creating a session cookie with firebase is because firebase only gives you one hour valid token, but with Hope this will help anyone, or maybe someone will give better solution. Thanks @sergiodxa 🙏 |
Beta Was this translation helpful? Give feedback.
Alright, so after reading article by @sergiodxa and another one I found, I was able to have it working properly.
https://sergiodxa.com/articles/working-with-refresh-tokens-in-remix
https://invertase.io/blog/remix-firebase-auth (In this article
firebase-admin
package is used but I have it on my go service, so everything done here withfirebase-admin
package is done externally in my case)Basically what I am doing is once user sign in/sign up I create a session cookie in
auth.server.ts
authenticator function and return it. The created session cookie has 5 days of validity and created with firebasecreateSessionCookie
function. Then I store it withsession.server.ts
with a longer validity (3…