Next.js Discord

Discord Forum

Not able to login

Unanswered
Flemish Giant posted this in #help-forum
Open in Discord
Flemish GiantOP
http://localhost:3000/en?username=test%40gmail.com&password=test%401234 i am using the next auth login but can not able to login it take 2-3 attempt to login and also the url shows the email id and password any tell me how to solve it

4 Replies

Nile Crocodile
can't do anything without seeing any code
Flemish GiantOP
@Nile Crocodile can't do anything without seeing any code
Flemish GiantOP
import { NextAuthOptions } from 'next-auth'
import CredentialsProvider from 'next-auth/providers/credentials'
import { ApiPostForm } from '../index'
import { GetMyUser } from 'api/users'

export const authOptions: NextAuthOptions = {
secret: process.env.NEXTAUTH_SECRET || 'zSLADSxHudaAtzEkWbPfbVaXa3D3Ls1Ey6f/Kn5YNVs=',
providers: [
CredentialsProvider({
name: 'Credentials',
type: 'credentials',
credentials: {
username: {
label: 'Email',
type: 'text'
},
password: { label: 'Password', type: 'password' }
},
authorize: async (credentials, _req) => {
try {
const response = await ApiPostForm('/auth/login', credentials)
if (response) {
const user = await GetMyUser(response.access_token)

if (user) return { ...user, token: response.access_token }
}
return null
} catch (error) {
console.log('ERROR while login')
return null
}
}
})
],
callbacks: {
async jwt({ token, user }: { token: any; user: any }) {
if (user) token.token = user.token
//console.log('callback jwt user', user)
return token
},
async session({ session, token }: { session: any; token: any }) {
const user = await GetMyUser(token.token)
if (user) session.user = { ...user, token: token.token }

return session
}
},
session: {
strategy: 'jwt',
maxAge: 24 * 60 * 60, // 30 days
updateAge: 24 * 60 * 60 // 24 hours
}
//debug: true
}
Please don’t repost the question in a new post