Describe the bug
A clear and concise description of the bug.
It work fine in localhost but when I deploy to vercel, Its redirect to login page infinite and have this log in login page before redirect and repeat this process again and again
next-firebase-auth: [withAuthUserSSR] Calling "withAuthUserSSR" / "withAuthUserTokenSSR". next-firebase-auth: [getUserFromCookies] Attempting to get user info from cookies via the ID token. next-firebase-auth: [getUserFromCookies] Failed to retrieve the ID token from cookies. This will happen if the user is not logged in, the provided cookie values are invalid, or the cookie values don't align with your cookie settings. The user will be unauthenticated. next-firebase-auth: [withAuthUserSSR] Redirecting to login.
I have the following setup:
Login page:
`import React, { useState } from 'react';
import { withAuthUser, AuthAction } from 'next-firebase-auth';
import { getAuth, signInWithEmailAndPassword } from 'firebase/auth';
import { initializeApp } from 'firebase/app';
import { Button, Steps } from 'antd';
import { Form } from 'antd';
import { Input } from 'antd';
import { decode as base64_decode } from 'base-64';
import { message } from 'antd';
import { useRouter } from 'next/router';
import Image from 'next/image';
import Logo from '@/assets/zenith-logo.png';
To Reproduce
Steps to reproduce the behavior:
After redirect to login I get
next-firebase-auth: [withAuthUserSSR] Calling "withAuthUserSSR" / "withAuthUserTokenSSR". next-firebase-auth: [getUserFromCookies] Attempting to get user info from cookies via the ID token. next-firebase-auth: [getUserFromCookies] Failed to retrieve the ID token from cookies. This will happen if the user is not logged in, the provided cookie values are invalid, or the cookie values don't align with your cookie settings. The user will be unauthenticated. next-firebase-auth: [withAuthUserSSR] Redirecting to login. and redirect to login again, creating an endless loop.
Expected behavior
A clear and concise description of what you expected to happen.
should be able to redirect the to /login correctly
Debug and error logs
Please provide debug logs or errors from onVerifyTokenError and onTokenRefreshError.
Additional context
Add any other context about the problem here.
When filing a bug report, please confirm you've done the following:
onVerifyTokenError
andonTokenRefreshError
in your config and checked for any helpful errors? yesdebug: true
in your config and read through server-side and client-side debug logs for any helpful messages? yesDescribe the bug A clear and concise description of the bug. It work fine in localhost but when I deploy to vercel, Its redirect to login page infinite and have this log in login page before redirect and repeat this process again and again
next-firebase-auth: [withAuthUserSSR] Calling "withAuthUserSSR" / "withAuthUserTokenSSR". next-firebase-auth: [getUserFromCookies] Attempting to get user info from cookies via the ID token. next-firebase-auth: [getUserFromCookies] Failed to retrieve the ID token from cookies. This will happen if the user is not logged in, the provided cookie values are invalid, or the cookie values don't align with your cookie settings. The user will be unauthenticated. next-firebase-auth: [withAuthUserSSR] Redirecting to login.
Vercel : vercel log
Infinite redirection :
https://www.example.com/login?destination=https%3A%2F%2Fwww.example.com%2Flogin%3Fdestination%3Dhttps%253A%252F%252Fwww.example.com%252Flogin%253Fdestination%253Dhttps%25253A%25252F%25252Fwww.example.com%25252Flogin%25253Fdestination%25253D ... and continue appending until the url is too long.
I have the following setup: Login page: `import React, { useState } from 'react'; import { withAuthUser, AuthAction } from 'next-firebase-auth'; import { getAuth, signInWithEmailAndPassword } from 'firebase/auth'; import { initializeApp } from 'firebase/app'; import { Button, Steps } from 'antd'; import { Form } from 'antd'; import { Input } from 'antd'; import { decode as base64_decode } from 'base-64'; import { message } from 'antd'; import { useRouter } from 'next/router'; import Image from 'next/image'; import Logo from '@/assets/zenith-logo.png';
const firebaseConfig = JSON.parse( base64_decode(process.env.NEXT_PUBLIC_FIREBASE_CONFIG) );
const Auth = () => { const [loading, setLoading] = useState(false); const app = initializeApp(firebaseConfig);
};
export default withAuthUser({ whenAuthed: AuthAction.REDIRECT_TO_APP, appPageURL: 'populations', })(Auth); `
Config: `import { init } from 'next-firebase-auth'; import absoluteUrl from 'next-absolute-url'; import { decode as base64_decode } from 'base-64';
const TWELVE_DAYS_IN_MS = 12 60 60 24 1000;
const initAuth = () => { const firebaseConfig = JSON.parse( base64_decode(process.env.NEXT_PUBLIC_FIREBASE_CONFIG) ); init({ debug: true, onVerifyTokenError: (err) => { console.log( 'π ~ file: initAuth.js ~ onVerifyTokenError ~ err:', err ); }, onTokenRefreshError: (err) => { console.log( 'π ~ file: initAuth.js ~ onTokenRefreshError ~ err:', err ); }, onLoginRequestError: (err) => { console.log( 'π ~ file: initAuth.js ~ onLoginRequestError ~ err:', err ); }, // This demonstrates setting a dynamic destination URL when // redirecting from app pages. Alternatively, you can simply // specify
authPageURL: '/auth-ssr'
. authPageURL: ({ ctx }) => { const isServerSide = typeof window === 'undefined'; const origin = isServerSide ? absoluteUrl(ctx.req).origin : window.location.origin; const destPath = typeof window === 'undefined' ? ctx.resolvedUrl : window.location.href; const destURL = new URL(destPath, origin); return/login?destination=${encodeURIComponent(destURL)}
; },};
export default initAuth; `
Versions
next-firebase-auth
version: 1.0.0-canary.19 Firebase JS SDK: 9.19.0 Next.js: latestTo Reproduce Steps to reproduce the behavior: After redirect to login I get
next-firebase-auth: [withAuthUserSSR] Calling "withAuthUserSSR" / "withAuthUserTokenSSR". next-firebase-auth: [getUserFromCookies] Attempting to get user info from cookies via the ID token. next-firebase-auth: [getUserFromCookies] Failed to retrieve the ID token from cookies. This will happen if the user is not logged in, the provided cookie values are invalid, or the cookie values don't align with your cookie settings. The user will be unauthenticated. next-firebase-auth: [withAuthUserSSR] Redirecting to login.
and redirect to login again, creating an endless loop.Expected behavior A clear and concise description of what you expected to happen. should be able to redirect the to /login correctly
Debug and error logs Please provide debug logs or errors from
onVerifyTokenError
andonTokenRefreshError
.Additional context Add any other context about the problem here.