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

fix: show experimental api warning only in dev and only once #4816

Merged
merged 6 commits into from Jul 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions packages/next-auth/src/next/index.ts
Expand Up @@ -85,18 +85,27 @@ export default NextAuth

export async function unstable_getServerSession(
...args:
| [GetServerSidePropsContext['req'], GetServerSidePropsContext['res'], NextAuthOptions]
| [
GetServerSidePropsContext["req"],
GetServerSidePropsContext["res"],
NextAuthOptions
]
| [NextApiRequest, NextApiResponse, NextAuthOptions]
): Promise<Session | null> {
console.warn(
"[next-auth][warn][EXPERIMENTAL_API]",
"\n`unstable_getServerSession` is experimental and may be removed or changed in the future, as the name suggested.",
`\nhttps://next-auth.js.org/configuration/nextjs#unstable_getServerSession}`,
`\nhttps://next-auth.js.org/warnings#EXPERIMENTAL_API`
let shown = false
ndom91 marked this conversation as resolved.
Show resolved Hide resolved

if (!shown || process.env.NODE_ENV !== "production") {
console.warn(
"[next-auth][warn][EXPERIMENTAL_API]",
"\n`unstable_getServerSession` is experimental and may be removed or changed in the future, as the name suggested.",
`\nhttps://next-auth.js.org/configuration/nextjs#unstable_getServerSession}`,
`\nhttps://next-auth.js.org/warnings#EXPERIMENTAL_API`
)
shown = true
}

const [req, res, options] = args

const [req, res, options] = args;

options.secret = options.secret ?? process.env.NEXTAUTH_SECRET

const session = await NextAuthHandler<Session | {}>({
Expand Down