curl --request POST \
--url https://api.example.com/api/auth/signin \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"password": "<string>"
}
'{
"Location": {},
"Set-Cookie": {},
"sb-access-token": {},
"sb-refresh-token": {},
"Retry-After": {}
}Authenticate an existing user with email and password
curl --request POST \
--url https://api.example.com/api/auth/signin \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"password": "<string>"
}
'{
"Location": {},
"Set-Cookie": {},
"sb-access-token": {},
"sb-refresh-token": {},
"Retry-After": {}
}429 Too Many Requests when limit is exceededapplication/x-www-form-urlencoded form data (typically from an HTML form submission).
[email protected]SecurePass123!/) with a 302 Found status code./curl -X POST "https://anidev.vercel.app/api/auth/signin" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "[email protected]&password=SecurePass123!" \
-L \
-c cookies.txt
302 Found (Redirect)
Headers:
Location: /
Set-Cookie: sb-access-token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...; HttpOnly; Secure; SameSite=Lax; Max-Age=604800; Path=/
Set-Cookie: sb-refresh-token=v1.MRjyg-VNJ8H7zN...; HttpOnly; Secure; SameSite=Lax; Max-Age=604800; Path=/
400 Bad Request
{
"error": "Email and password are required",
"type": "validation"
}
401 Unauthorized
{
"error": "Invalid email or password",
"type": "unauthorized"
}
401 Unauthorized
{
"error": "No user found with this email",
"type": "unauthorized"
}
429 Too Many Requests
{
"error": "Too many requests, please try again later",
"type": "tooManyRequests"
}
500 Internal Server Error
{
"error": "Internal server error"
}
// Check if user is authenticated
const checkAuth = async () => {
try {
const response = await fetch('/api/auth/session', {
credentials: 'include'
});
if (response.ok) {
const session = await response.json();
return session.user;
}
} catch (err) {
console.error('Not authenticated');
}
return null;
};
// Use in your app
const user = await checkAuth();
if (!user) {
// Redirect to sign in page
window.location.href = '/signin';
}
/ (homepage).To customize the redirect destination, you can:redirect query parameter to the form actionreturnTo parameter---
// signin.astro
const error = Astro.url.searchParams.get('error');
---
<form action="/api/auth/signin" method="POST">
<input
type="email"
name="email"
placeholder="Email"
required
/>
<input
type="password"
name="password"
placeholder="Password"
required
/>
{error && <p class="error">{error}</p>}
<button type="submit">Sign In</button>
<p>
Don't have an account?
<a href="/signup">Sign up</a>
</p>
</form>