Skip to main content

auth

Authenticate a user.

Description​

Authenticates a user with an auth provider and resolves to an IAuthEntity with the user's accessToken and refreshToken.

On success the SDK stores the tokens and calls saveFunction. If the provider has isCheckCode enabled, the user can sign in with a one-time code instead of a password: send an authData entry with the marker code and the code from generateCode().

.auth(

,

);

Parameters schema​

Schema

marker(required): string
Marker of the auth provider.
example: "email"

body(required): IAuthPostBody
Authentication data.
example:

{
"authData": [
{
"marker": "login",
"value": "john@example.com"
},
{
"marker": "password",
"value": "12345"
}
]
}

body.authData(required): IAuthData[]
Authentication fields, each with a marker and a value.
example:

[
{
"marker": "login",
"value": "john@example.com"
}
]

authData.marker(required): string
Marker of the auth form field.
example: "login"

authData.value(required): string
The value of the auth field.
example: "john@example.com"

Examples​

Minimal example​


const body = {
{
,
},
{
,
}
]
};

const response = await AuthProvider.auth('email', body);

Example response​

{
"userIdentifier": "john@example.com",
"authProviderIdentifier": "email",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX...",
"refreshToken": "1793092445696-10324d05-566d-4fb7..."
}

Response schema​

Schema: IAuthEntity

userIdentifier: string
User identifier (login), for example the email address.
example: "user12345"

authProviderIdentifier: string
Marker of the authentication provider.
example: "email"

accessToken: string
The access token for the user session.
example: "abcdef123456"

refreshToken: string
The refresh token for renewing the access token.
example: "ghijkl789012"


Usage examples​

Step-by-step walkthroughs in the documentation:

  • Update user: authenticate, then update the user's profile fields.
  • Order history: authenticate the user, then fetch their personal order history.
  • Order pay: authenticate before placing and paying for an order.
  • Order subscription: authenticate, then check for an active subscription.
  • Tickets order: authenticate as part of the tickets checkout flow.
  • Guest order: log in as a guest before placing an order.
  • Register user: authenticate immediately after sign-up.

Try it live​

The same scenarios, plus Password reset, run in the JS SDK sandbox. Connect your Project URL and App Token on first visit.