Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't refresh some pages #154

Open
Tockra opened this issue Oct 10, 2024 · 2 comments
Open

Can't refresh some pages #154

Tockra opened this issue Oct 10, 2024 · 2 comments

Comments

@Tockra
Copy link

Tockra commented Oct 10, 2024

Hello,

after I built my application in a docker container and run it there, I have problems while refreshing some pages.
I say some, because some pages can be reloaded, some pages not.
I've no idea why.

But the console message in my browser indicates that some variables in my auth provider are not set correctly. But I am very confused why.
It is caused by the env loading:

My provider:

"use client";

import React, { PropsWithChildren } from "react";

import { AuthProvider } from "react-oidc-context";

import { env } from "next-runtime-env";

export function AuthProviderWrapper({ children }: PropsWithChildren) {
  const NEXT_PUBLIC_AUTH_URL = env("NEXT_PUBLIC_AUTH_URL") ?? "";
  const NEXT_PUBLIC_AUTH_AUTHORITY_PATH =
    env("NEXT_PUBLIC_AUTH_AUTHORITY_PATH") ?? "";
  const NEXT_PUBLIC_AUTH_CLIENT_ID = env("NEXT_PUBLIC_AUTH_CLIENT_ID") ?? "";
  const NEXT_PUBLIC_AUTH_REDIRECT_URI =
    env("NEXT_PUBLIC_AUTH_REDIRECT_URI") ?? "";

  const oidcConfig = {
    authority: NEXT_PUBLIC_AUTH_URL + NEXT_PUBLIC_AUTH_AUTHORITY_PATH,
    client_id: NEXT_PUBLIC_AUTH_CLIENT_ID,
    redirect_uri: NEXT_PUBLIC_AUTH_REDIRECT_URI,
    loadUserInfo: true,
  };

  return <AuthProvider {...oidcConfig}>{children}</AuthProvider>;
}

I added some logging which says that after reload the page in the browser, my env("NEXT_PUBLIC_AUTH_URL") ?? ""(and all other calls) are evaluated to "" which causes my application to crash.
Only if I visit my main page (mydomain.de) everything is loaded fine again.
While navigation through the pages there is no issue.

Only on refresh the page. Maybe this is related with next-intl (???).

Does anybody has a hint how to fix that without removing the usage of next-runtime-env ?

T

@tpjnorton
Copy link

This is happening too for me - when I have my app deployed to Vercel sometimes on reload none of my runtime env vars are actually set - this disappears with a hard refresh, and sparingly with a regular refresh.

@Tockra
Copy link
Author

Tockra commented Oct 25, 2024

I'm not sure anymore but my problem was caused by some Wrapper in my layout.tsx which was on the wrong level.
After some cleanup there it worked again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants