Auth0 Stable Support For Next.js App Router!

Let’s explore the main features of the new Auth0 SDK for NextJS release.
Read more…

:writing_hand:t2: Brought to you by @juan.martinez

Hey folks! We’re happy to help if you have any questions!

1 Like

With the release of NextJS 14, I am moving a lot of our data fetching and mutation logic for our backend API into Server Actions in an isolated DAL. Can I use the nextjs-auth0 SDK with Server Actions or do I need to call the Auth0 Authentication API directly?

Hi @jenergy, how are you?

It is possible to secure and obtain information from your session while using server actions directly from the SDK.

We have an article covering server actions, but here are the basics of it.

On a server action you can either obtain the user information from the session or the access token in case you need to call a third party API.

Here is an example of capturing the access token on a server action:

'use server'
import { getAccessToken } from '@auth0/nextjs-auth0'

export async function someAction() {
  const accessToken = await getAccessToken();
}

or you can access the session with:

import { getAccessToken } from '@auth0/nextjs-auth0'

export async function someAction() {
  const session = await getSession();
  if (session) {
    ... // e.g. session.user
  }
}

Does this help?