Skip to content
Community forum

access_token is undefined after a successful login

SolvedSupero SupportSupero team asked

Common question, written up by the Supero team.

Login returns 200, but the token comes out empty and every call after it is rejected:

js
const res = await fetch('https://api.supero.dev/api/v1/auth/login', { method: 'POST', headers, body });
const { access_token } = await res.json();   // undefined
Link

1 answer

Accepted answer
Accepted answer

The login response isn't flat. It has four blocks, auth, user, context and policy, and the tokens sit inside auth:

js
const { auth } = await res.json();
headers.Authorization = `Bearer ${auth.access_token}`;
// auth.refresh_token, auth.expires_in (28800), auth.session_id

The refresh call is shaped differently. You send the refresh token as the Bearer credential to POST /api/v1/auth/refresh, and that response does carry access_token at the top level, so don't reuse the login parsing for it.

On the request side, login takes domain; domain_name is accepted as an alias there, and domain wins if you send both. User registration is the other way round and takes domain_name.

Supero Platform teamSupero team answered
Link

Your answer

access_token is undefined after a successful login | Supero Community