| title | Login |
|---|---|
| description | Authenticate a user with email and password and receive an access token. |
Validates the user's credentials and returns a short-lived JWT access token. A refresh token is also issued to keep the session alive without requiring the user to log in again.
x-api-key: your pk_live_… key.
The refresh token is issued alongside the access token and delivered differently depending on the client type:
- Web (browser): issued as an HTTP-only cookie. Your browser stores and sends it automatically — you do not need to handle it manually.
- Mobile / non-browser: returned in the
x-refresh-tokenresponse header. Store it securely and include it when calling/api/userAuth/refresh-token.
const res = await fetch('https://api.urbackend.in/api/userAuth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'pk_live_YOUR_KEY'
},
credentials: 'include', // Include for web: stores the refresh cookie
body: JSON.stringify({
email: 'alice@example.com',
password: 'securePassword123'
})
});
const { accessToken, expiresIn, user } = await res.json();curl -X POST "https://api.urbackend.in/api/userAuth/login" \
-H "Content-Type: application/json" \
-H "x-api-key: pk_live_YOUR_KEY" \
-c cookies.txt \
-d '{
"email": "alice@example.com",
"password": "securePassword123"
}'{
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expiresIn": "15m",
"user": {
"_id": "64fd1234abcd5678ef901234",
"email": "alice@example.com",
"name": "Alice"
}
}| Status | Cause |
|---|---|
400 Bad Request |
Missing email or password |
401 Unauthorized |
Invalid credentials |