Skip to main content
POST
/
api
/
auth
/
signin
Sign In
curl --request POST \
  --url https://api.example.com/api/auth/signin \
  --header 'Content-Type: application/json' \
  --data '
{
  "email": "<string>",
  "password": "<string>"
}
'
{
  "user": {
    "id": 123,
    "email": "<string>",
    "name": "<string>"
  },
  "accessToken": "<string>",
  "isEmailVerified": true,
  "verificationToken": {}
}

Overview

Authenticates a user using NextAuth’s credentials provider. This endpoint validates the user’s email and password, and returns a session with JWT tokens for subsequent API requests.
Noteverse uses NextAuth for authentication with a JWT session strategy. Sessions are valid for 30 days by default.

Authentication Flow

The sign-in process uses NextAuth’s CredentialsProvider with the following flow:
  1. User submits email and password
  2. System validates credentials against the database
  3. Password is compared using bcrypt
  4. On success, JWT token is created with user data and auth token
  5. Session is established with access to user ID, email, and verification status

Request

Body Parameters

email
string
required
The user’s email address registered in the system.
password
string
required
The user’s password in plain text. Will be compared against the hashed password in the database.

Response

NextAuth handles the response automatically. On successful authentication, a session is created containing:
user
object
User information object.
id
number
The user’s unique identifier.
email
string
The user’s email address.
name
string
The user’s username.
accessToken
string
The user’s authentication token (authToken from database) for API requests.
isEmailVerified
boolean
Whether the user has verified their email address.
verificationToken
string | null
The verification token if email is not yet verified, null otherwise.

Status Codes

  • 200 OK - Authentication successful, session created
  • 401 Unauthorized - Invalid credentials or user not found
  • 400 Bad Request - Missing email or password

Examples

curl -X POST https://your-domain.com/api/auth/signin \
  -H "Content-Type: application/json" \
  -d '{
    "email": "alice@example.com",
    "password": "SecurePass123!"
  }'

Success Response (200)

{
  "user": {
    "id": 1,
    "email": "alice@example.com",
    "name": "Alice Johnson"
  },
  "accessToken": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6",
  "isEmailVerified": true,
  "verificationToken": null
}

Error Response (401)

{
  "error": "Authorization error: Error: Invalid password"
}

Error Cases

Authentication Errors: The endpoint returns specific error messages for different authentication failures to help diagnose issues while maintaining security.

Common Error Scenarios

  1. Missing Credentials
    • Status: 401
    • Cause: Email or password not provided in request body
    • Response: null user (handled by NextAuth)
  2. User Not Found
    • Status: 401
    • Message: “Authorization error: Error: No user found”
    • Cause: No user exists with the provided email
  3. Invalid Password
    • Status: 401
    • Message: “Authorization error: Error: Invalid password”
    • Cause: Password doesn’t match the hashed password in database
  4. Database Error
    • Status: 401
    • Message: “Authorization error: [error details]”
    • Cause: Database connection or query error

Implementation Details

  • Session Strategy: JWT tokens with 30-day expiration
  • Password Verification: bcrypt comparison of plain text password against hashed password
  • Token Generation: Auth token is retrieved from the database and included in the session
  • Email Verification: Users can sign in before verifying email, but isEmailVerified flag indicates verification status

JWT Token Contents

The JWT token includes:
  • User ID
  • Access token (authToken from database)
  • Email verification status
  • Verification token (if email not verified)

Session Object

The session object accessible via getSession() includes:
  • user.id: User’s database ID
  • user.email: User’s email
  • user.name: User’s username
  • accessToken: For authenticated API requests
  • isEmailVerified: Email verification status
  • verificationToken: For email verification if needed

Alternative Authentication

Noteverse also supports Google OAuth authentication. Users who sign in with Google automatically have their email verified and don’t require password credentials.

Next Steps

After successful sign-in:
  1. Store the session token for subsequent authenticated requests
  2. Check isEmailVerified status
  3. If email is not verified, prompt user to verify using the Verify Email endpoint
  4. Use the accessToken for authenticated API requests to other endpoints

Build docs developers (and LLMs) love