Questions tagged [next-auth]

NextAuth.js is a open source authentication solution for Next.js applications. This tag is rarely used alone and is most often used in conjunction with [next.js]

1602 questions
13
votes
3 answers

How can I add a new property to Component in _app.tsx in Next.js with Typescript?

I'm developing some protected pages using Next.js, NextAuth.js and Typescript. The following code from my _app.tsx was taken from the NextAuth.js official website but that includes a property auth that does not exist for Component which has the type…
Alexandre Paiva
  • 987
  • 2
  • 10
  • 24
13
votes
5 answers

How to redirect in NextJS if not logged using nextAuth

I am using nextAuth for authentication in my project and I would like to restrict certain pages for the clients that are not logged in. I tried calling the useSession() hook in the getServerSideProps() function but I got an error for calling the…
Benni
  • 554
  • 2
  • 8
  • 19
13
votes
2 answers

Redirect after successful sign in or sign up for credentials type in next auth

Is there any examples and/or way to redirect to private dashboard on successful sign in or sign up for credentials type in next-auth? I couldn't find any clear docs around this. I was looking at adding redirect below but wasn't sure if it was the…
Passionate Engineer
  • 10,034
  • 26
  • 96
  • 168
12
votes
5 answers

Next-auth - How to update the session client side?

I manage to update my session serverside, with new user data, but event after assigning it to my session object in [...nextauth.js], my session client side remains the old one. It doesn't refresh, event if I use getSession(). This code works for the…
Yoann Buzenet
  • 651
  • 2
  • 5
  • 12
12
votes
2 answers

Next-Auth with Provider.Credentials: How to implement when API is already returning a JWT Token?

I have a NextJS page where I try to implement Next-Auth. I use credentials to login to my Rails API. My API is returning (already) a JWT-Token. (so NextAuth must not create it) How to implement the Provider.Credentials for [...nextauth].js in that…
Jan
  • 12,992
  • 9
  • 53
  • 89
12
votes
8 answers

How to fix api/auth/error issue of next-auth in production?

I have set the following environment variables in Vercel: NEXTAUTH_URL=https://example.vercel.app (production) NEXTAUTH_URL=http://localhost:3000 (development) Then authorized the following two redirect URLs in Google provider GCP console…
Fuad9
  • 353
  • 1
  • 3
  • 19
12
votes
4 answers

How to update session values without signing out?

With NextAuth.js, how can I update a value inside the session object without signing out and in again? For example, once a user signs in, I am using the URL stored in the session to display the avatar of the user. I am also offering the user to…
Pingolin
  • 3,161
  • 6
  • 25
  • 40
11
votes
3 answers

How do I use next auth getServerSession in next js 13 beta server component in app directory

I'm using next auth v4 with next js 13 beta with server component, and everything works fine. But I have a situation where I will need to know the logged user id, since I'm using next auth, I have access to the session, I can use useSession() but…
Shakib Hasan
  • 231
  • 1
  • 1
  • 8
11
votes
2 answers

Why am I getting this error when using Next.js middleware?

The Problem I'm using Next.js, Prisma, and NextAuth's Email Provider strategy to setup an authentication system. I want to use Next.js middleware to redirect a request if it doesn't contain a valid session. But any use of the middleware, like…
rolias4031
  • 233
  • 2
  • 10
11
votes
1 answer

how to update the type of session in session callback in Next-auth when using Typescript

I am using typescript and my [...next-auth].tsx file looks like this: import NextAuth, { Awaitable, Session, User } from "next-auth"; // import GithubProvider from "next-auth/providers/github"; import GoogleProvider from…
Vikrant Bhat
  • 2,117
  • 2
  • 14
  • 32
11
votes
2 answers

nextjs & next-auth getSession() in getServerSideProps with HTTPS not work

I cant use getSession() in getServerSideProps with HTTPS. is it normal? I try many times. I will get it if use HTTPS . I cant getSession() in …
scxsk0992
  • 147
  • 1
  • 1
  • 8
11
votes
3 answers

Getting NextAuth.js user session in Apollo Server context

My web app is using: NextJS NextAuth.js Apollo Server I have a NextAuth set up in my app, and I am able to log in just fine. The problem is coming from trying to get access to the user's session in the Apollo context. I want to pass my user's…
Nolan P
  • 147
  • 1
  • 4
11
votes
2 answers

What is the 'loading' return value from useSession() in next-auth?

I'm writing a Next.js project, and implementing authentication using GitHub and next-auth. In the examples of next-auth, there's a call to useSession(), which returns two objects: session and loading. However, none of the examples that I've seen…
user189198
10
votes
1 answer

How to mutate user's session in nextauth when you change user data?

I want to update the user's data but after updating the user's data how to make also the change appear in session? [...nextauth].js callbacks: { jwt: ({ token, user }) => { if (user) { token.id = user.id; token.name =…
n9p4
  • 304
  • 8
  • 34
10
votes
2 answers

Playwright e2e testing. What to do with oauth2 or email-passwordless authentication

I am starting to do e2e tests with playwright. Most of the application requires to be authenticated. Automating this with a username/password mechanism is quite easy. The problem is that the app I want to test has only two authentication mechanisms:…