Skip to main content

Login

Authenticate and get access token.

Endpoint

POST /api/Authentication/login

Request Body

{
"email": "[email protected]",
"password": "password"
}

Parameters

ParameterTypeRequiredDescription
emailstringYesUser email address
passwordstringYesUser password

Response

Success (200 OK)

{
"success": true,
"data": {
"token": "eyJhbGciOiJIUzI1NiIs...",
"refreshToken": "refresh-token-here",
"expiresIn": 3600,
"user": {
"id": "user-id",
"email": "[email protected]",
"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}`
}
});

Next Steps