Custom Login with NextJS Passwordless

Hi I’m currently implementing a passwordless login/signup flow on our NextJS web app. Have been banging my head against a wall. Currently I get my user_id and access token after creating a user or verifying a code with /oauth/token and /api/v2/users respectively. I’m stumped on how to proceed after getting my user_id and access token and how to actually log user in, create session etc.

With the sdk it looks like this all handled for you with useUser() hook but since not using the SDK have been stumped.

I’ve looked at

and the code samples for vanilla js at

but haven’t been able to make headway.

code for creating a user (run as a serverless function)
const create_res = await fetch(${process.env.AUTH0_ISSUER_BASE_URL}/api/v2/users, {
method: ‘POST’,
headers: {‘content-type’: ‘application/json’, authorization: Bearer ${process.env.AUTH0_ACCESS_TOKEN}},
body: JSON.stringify({
“email”: req.body[INPUT_NAMES.EMAIL],
“phone_number”: req.body[INPUT_NAMES.PHONE],
“blocked”: false,
“email_verified”: false,
“phone_verified”: false,
“name”: req.body[INPUT_NAMES.NAME],
“connection”: “sms”


code for verifying user (run as serverless function)

const verify_res = await fetch(${process.env.AUTH0_ISSUER_BASE_URL}/oauth/token, {
method: ‘POST’,
headers: {‘content-type’: ‘application/json’},
body: JSON.stringify({
client_id: ${process.env.AUTH0_CLIENT_ID},
client_secret: ${process.env.AUTH0_CLIENT_SECRET},
grant_type: “”,
otp: req.body.code,


I get the user_id and access_token from these calls but would appreciate advice on what to do next or if there’s an example you could point me towards would be great. Thanks so much!