Authentication Setup
This guide covers setting up user authentication with Conduit, including local authentication and OAuth providers.
Prerequisites
- Conduit installed and running
- Authentication module deployed
Local Authentication
Create a User
curl -X POST 'http://localhost:3000/authentication/local/new' \
-H 'Content-Type: application/json' \
-d '{
"email": "user@example.com",
"password": "securepassword"
}'
Response:
{
"user": {
"email": "user@example.com",
"active": true,
"isVerified": false,
"_id": "..."
}
}
Login
curl -X POST 'http://localhost:3000/authentication/local' \
-H 'Content-Type: application/json' \
-d '{
"email": "user@example.com",
"password": "securepassword"
}'
Response:
{
"accessToken": "eyJhbGciOiJIUzI1NiIs...",
"refreshToken": "aDYLqHPw6yK+GTNsWApA..."
}
Making Authenticated Requests
Include the access token in the Authorization header:
curl -X GET 'http://localhost:3000/some-protected-route' \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN'
Logout
curl -X POST 'http://localhost:3000/authentication/logout' \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN'
OAuth Configuration
Enable OAuth Provider
- Open Admin Panel > Authentication > Settings
- Navigate to OAuth providers section
- Enable your desired provider
- Enter your OAuth credentials (Client ID, Client Secret)
Supported Providers
- GitHub
- Microsoft
- Apple
- Slack
- Twitch
- GitLab
- Bitbucket
- Figma
OAuth Flow Example (Google)
-
Initiate OAuth:
GET http://localhost:3000/authentication/google -
User authenticates with Google
-
Callback returns tokens:
{
"accessToken": "...",
"refreshToken": "..."
}
Two-Factor Authentication
Enable 2FA
- Configure SMS module (required for OTP)
- Enable 2FA in Authentication settings
- Users can enable 2FA from their profile
2FA Flow
- User logs in with credentials
- Server responds with 2FA required
- User enters OTP code
- Access granted
Managing Users (Admin Panel)
Create User
Navigate to Authentication > Users > Add User
Edit User
- Change email
- Add phone number
- Enable/disable 2FA
- Reset password
Block/Unblock Users
Select users and use the Block/Unblock action for access control.
Best Practices
- Enable email verification for production
- Use HTTPS in production environments
- Store tokens securely on the client side
- Implement token refresh logic
- Set appropriate token expiration times
Next Steps
- Configure Authorization for role-based access
- Set up Email for verification emails
- Learn about Magic Links for passwordless auth