firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Error 403 on next js redirect SSR

Open lucasoz opened this issue 2 years ago • 2 comments

[REQUIRED] Environment info

firebase-tools: 12.6.1

Platform: Ubuntu

[REQUIRED] Test case

Hi, I'm using next 13 with pages directory and I'm trying to use a simple redirection from a page to another with server side rendering and I'm getting a 403 error

image

[REQUIRED] Steps to reproduce

Create a next js 13 app with pages directory:

  1. npx create-next-app@latest What is your project named? my-app Would you like to use TypeScript? Yes Would you like to use ESLint? Yes Would you like to use Tailwind CSS? Yes Would you like to use src/ directory? No Would you like to use App Router? (recommended) No Would you like to customize the default import alias (@/)? Yes What import alias would you like configured? @/

  2. Create a folder example and a file index.tsx inside with the following:

export function getServerSideProps() {
  return {
    redirect: {
      destination: "/",
      permanent: false,
    },
  };
}

export default function Index() {
  return <div>Example</div>;
}
  1. Deploy with firebase hosting https://firebase.google.com/docs/hosting/frameworks/nextjs?hl=es-419
  2. Enter your-domain.com/example` page in the browser

[REQUIRED] Expected behavior

Redirection works

[REQUIRED] Actual behavior

Redirection is getting a 403 error

lucasoz avatar Oct 03 '23 16:10 lucasoz

The deployment creates any SSR code as a cloud function - I encountered this same issue and was able to work around it by updating my IAM settings for both Cloud Functions and Cloud Run in my Google Cloud Console.

https://cloud.google.com/functions/docs/securing/authenticating?&_ga=2.197954991.-1080258126.1678554131#authenticating_function_to_function_calls

https://cloud.google.com/run/docs/authenticating/public

Hope this helps.

kevineleven avatar Oct 17 '23 02:10 kevineleven

Hey @lucasoz, as @kevineleven mentioned in the comment above, your Cloud Fuction(Next.js server) should be publicly accessible. It's public by default but your organization policy can change that.

Please confirm if allowing public access fixes the issue for you.

leoortizz avatar Jun 18 '24 19:06 leoortizz

Hey @lucasoz. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Jul 09 '24 01:07 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@lucasoz if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Jul 12 '24 01:07 google-oss-bot