Login
Authenticate and get access token.
Endpoint
POST /api/Authentication/login
Request Body
{
"password": "password"
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Yes | User email address | |
| password | string | Yes | User password |
Response
Success (200 OK)
{
"success": true,
"data": {
"token": "eyJhbGciOiJIUzI1NiIs...",
"refreshToken": "refresh-token-here",
"expiresIn": 3600,
"user": {
"id": "user-id",
"fullName": "John Doe",
"username": "johndoe"
}
}
}
Error (401 Unauthorized)
{
"success": false,
"error": {
"code": "INVALID_CREDENTIALS",
"message": "Invalid email or password"
}
}
Example
const response = await fetch('http://localhost:5000/api/Authentication/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
password: 'password'
})
});
const data = await response.json();
localStorage.setItem('token', data.data.token);
Token Usage
Include the token in subsequent requests:
fetch('http://localhost:5000/api/Post/feed/home', {
headers: {
'Authorization': `Bearer ${token}`
}
});