#next-auth

1 messages · Page 1 of 1 (latest)

unique sky
#

Hey!

There's a guide on using a custom provider here
https://next-auth.js.org/configuration/providers/oauth#using-a-custom-provider

And examples of a custom login page here
https://next-auth.js.org/configuration/pages#examples

Do you have an example of the error you are facing?

Unfortunately next-auth is a different project to nextjs so support is limited to the discussions tab over at https://github.com/nextauthjs/next-auth

GitHub

Authentication for Next.js. Contribute to nextauthjs/next-auth development by creating an account on GitHub.

NextAuth.js automatically creates simple, unbranded authentication pages for handling Sign in, Sign out, Email Verification and displaying error messages.

Authentication Providers in NextAuth.js are OAuth definitions that allow your users to sign in with their favorite preexisting logins. You can use any of our many predefined providers, or write your own custom OAuth configuration.

flint torrent
#

Hello, ```import NextAuth from "next-auth"
import CredentialsProvider from "next-auth/providers/credentials"
import axios from "axios"
// import AppleProvider from "next-auth/providers/apple"
// import EmailProvider from "next-auth/providers/email"

// For more information on each option (and a full list of options) go to
// https://next-auth.js.org/configuration/options
export default NextAuth({
// https://next-auth.js.org/configuration/providers/oauth
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
username: { label: "Username", type: "text", placeholder: "jsmith" },
password: { label: "Password", type: "password" },
},
async authorize(credentials, req) {
try {
const result = await axios.post(
"http://localhost:3000/api/credentials/login",
credentials
)
console.log(result.data)
return result.data
} catch (error) {
//console.log(error)
return null
}
},
}),
],
theme: {
colorScheme: "light",
},
callbacks: {
async jwt({ token }) {
token.userRole = "admin"
return token
},
async session({ session, token, user }) {
console.log(user)
console.log(token)
console.log(session)
token.userRole = "admin"
return session
},
},
})

#

because the docs are saying // Any object returned will be saved in `user` property of the JWT but thats not working on my site

unique sky
# flint torrent Hello, ```import NextAuth from "next-auth" import CredentialsProvider from "next...

Hey! I think you need to change

token.userRole = "admin"

to

session.userRole = 'admin'

Or

session.userRole = token.userRole 
```(which you set in the jwt callback)

in the session callback as per https://next-auth.js.org/configuration/callbacks

Also in future please ask in [#community-help](/guild/752553802359505017/channel/752668543891276009/) (this thread was created to answer a question in [#discussions](/guild/752553802359505017/channel/752647196419031042/)), but as next-auth isn't part of the nextjs project the official support channel is through the github discussions which I linked in a previous method in this thread.

Callbacks are asynchronous functions you can use to control what happens when an action is performed.

pulsar tide
#

Hey if I can use this thread as well, I am new to Next-Auth.js and simply can't figure out how to get it working

#

I literally cloned the Next-Auth_Example, followed the instructions in the ReadMe but it is still coming up with errors

#

(and yeah I did npm install)

#

@rare heath @unique sky @flint torrent I'm not sure how threads work will you guys see this

unique sky
pulsar tide
#

yep

unique sky
#

interesting.. seems to work fine for me

pulsar tide
#

Yeah that was also me :/

flint torrent
#

// More on how NextAuth.js middleware works: https://next-auth.js.org/configuration/nextjs#middleware
export default withAuth({
  callbacks: {

    authorized: ({ token }) => token?.userRole === "admin",
  },
})
``` hey, i started out with nextjs and im using the mongodb adapter. If i understood it correctly, nextauth is using session with mongodb. So my question is, how can i do the above with session instead of jwt?