Login as Local or Guest
The Auth Flows for login as Local Account or Guest
Log in with Local Account
This flow verifies that a user can successfully register a local account and then log in.
Step 1: Register Local Account
- Call
POST /api/auth/registerwith the following request body:
{
"firstName": "Cersei",
"lastName": "Lannister",
"email": "cersei-lannister@gmail.com",
"password": "C3rs3i#L4nnist3r",
"passwordConfirm": "C3rs3i#L4nnist3r"
}
Or
{
"firstName": "Cersei",
"lastName": "Lannister",
"username": "cersei-lannister",
"password": "C3rs3i#L4nnist3r",
"passwordConfirm": "C3rs3i#L4nnist3r"
}
- Expect a
200 OKresponse with the following body:
{
"success": true
}
Only valid email registration will require an email confirmation, if register with no email step 2 is not required
Step 2: Confirmation email with sent code (required for email registration only)
- Call
GET /api/auth/confirm-email/:verifyToken, where:verifyTokenis the verification token sent to the user's email address. - Expect a
200 OKresponse with the following body:
{
"success": true,
"message": "Email verified"
}
Step 3: Login with password and username or email
- Call
POST /api/auth/loginwith the following request body:
{
"type": "password",
"clientId": "client-app-id",
"withPassword": {
"emailOrUsername": "cersei-lannister@gmail.com",
"password": "C3rs3i#L4nnist3r"
}
}
- Expect a
200 OKresponse with anaccessTokenproperty.
{
"accessToken": "...",
"refreshToken": "..."
}
If login without email confirmation, access token will still issue, but any subsequence call will be blocked with 401 http status error and message 'Email is not verified'.
Only /api/auth//resend-email-verification api is callable at this point
Log in as Guest Account
Step 1: Login as Guest
- Call
POST /api/auth/loginwith the following request body:
{
"type": "guest",
"clientId": "client-app-id",
"asGuest": {
"username": "cersei-lannister@gmail.com"
}
}
If using random username, pass asGuest = {}
- Expect a
200 OKresponse with anaccessTokenproperty.
{
"accessToken": "...",
"refreshToken": "..."
}
Addtionally includes device and location info
Login method include some extra fields to include device and location infomation along with user credential data, this kind of info will be store as last logged in info for administrator purposes
{
//... credential data
"deviceInfo": {
"deviceType": "string",
"os": "string",
"browser": "string",
"deviceId": "string",
"deviceBrand": "string",
"deviceModel": "string"
},
"locationInfo": {
"latitude": 0,
"longitude": 0,
"city": "string",
"state": "string",
"country": "string"
}
}
Use Access Token to access other API
After logging in, you can use the access token to authenticate subsequent requests to your server by attaching authorization header Bearer ...
curl -X GET \
https://example.com/api \
-H 'Authorization: Bearer your_token_here'
Related API Endpoints
POST /api/auth/register: Register new accountGET /api/auth/confirm-email/:verifyToken: Confirm email adress with provide tokenPOST /api/auth/login: Login user.POST /api/auth/link/google: Link account with google.