-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Documentation on Local Dev / Credentials Incomplete #10711
Comments
Here's a workable solution I ended up with today.
With these two in place i can pass the session down from the layout to the child components. Typescript was causing huge issues and changing
One of the most painful parts of this was the piecemeal nature of the information I needed to form this solution. I referenced both the v4 and v5 docs, it was extremely difficult to find more documentation on the auth options and in which files the config or just the imports belong. The v5 docs need some sort of review from the perspective of "can somebody go through this page and actually use it". What I have provided above is a complete enough solution that someone can get it working without spending days bouncing between v4 and v5 docs. I hope someone can determine what from my solution is appropriate to add to the docs to address the concerns I raised above. |
Sorry you had such a hard time getting this setup, it looks like you've got some v4 and v5 things mixed up. For v5 if you follow the docs step-by-step starting with a "clean" (i.e. remove all previous auth.js/next-auth related stuff) Next.js project from the "Installation" page, you should be good to go. In v5, the
The rest of the config goes in your Also we have an example app you can always look at here |
For your testing use-case, I think you were on the right track. Basically if |
Also did you need to overwrite some AUTH_AZURE_AD_ID
AUTH_AZURE_AD_SECRET
AUTH_AZURE_AD_TENANT_ID // auth.ts
import NextAuth from "next-auth"
import AzureAD from "next-auth/providers/azure-ad"
import Credentials from "next-auth/providers/credentials"
import type { Provider } from "@auth/sveltekit/providers"
var providers: Provider[] = [];
if (process.env.NODE_ENV === "development") {
providers.push(
Credentials({
id: "password",
name: "Password",
credentials: {
password: { label: "", type: "password" },
},
authorize: (credentials) => {
if (credentials.password === "password") {
return {
email: "test@test.com",
name: "Test User",
image: "https://avatars.githubusercontent.com/u/67470890?s=200&v=4",
}
}
},
})
)
} else {
providers.push(AzureAD)
}
export const { handlers, auth, signIn, signOut } = NextAuth({
debug: true,
providers,
}) I would do the This is all just following the examples mostly in the "Installation", "Session Management/*" and "Testing" pages 😊 EDIT: Promise this is the last follow-up / FYI haha - we released an "Microsoft Entra ID" provider (which is mostly just a rebadged "AzureAD" provider) in |
What is the improvement or update you wish to see?
Desired Improvements: Testing missing examples on how to deal with dev / prod
https://authjs.dev/guides/testing
/api/auth/[...nextauth]/route.js
and/auth.ts
This feels like either a gaping hole of functionality / documentation re: local dev... or more likely I am REALLY missing something that should be obvious in the docs but I'm not getting it.
Problem:
Currently only a small snippet of
/auth.js
is available on the testing guide and there is not enough context or information to get a working solution.What do I put in the
[...nextauth]/route.js
? For Azure AD I define a clientID, secret and tennant... but for credentials?Also of note, the Credentials provider has zero documentation on what to put in that route. Should I just remove it?
https://authjs.dev/getting-started/providers/credentials
Is there any context that might help us understand?
When using an OAuth provider, it's not possible or easy (or documented how) to setup a next.js app to authenticate against a system like Azure AD or Auth0 because your system needs to do the callback stuff to process the flow correctly.
The solution provided in the docs makes sense... use a different provider.
I get tons of errors and things break and explode when I try to configure things as described in the
if (process.env.NODE_ENV === "development")
solution.What it proposes is EXACTLY what I need, unfortunately the docs advertise code that doesn't work.
Does the docs page already exist? Please link to it.
https://authjs.dev/guides/testing
The text was updated successfully, but these errors were encountered: