Authentication
Auktiva uses NextAuth.js v4 for authentication, supporting both credentials-based login and OAuth providers (Google).
Configuration
Required Environment Variables
# Secret key for encrypting sessions
AUTH_SECRET="your-secret-key-here"
# Base URL of your application
AUTH_URL="http://localhost:3000"Generating AUTH_SECRET
Always generate a unique, random secret for production:
# Using OpenSSL
openssl rand -base64 32
# Using Node.js
node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"Never use the example secret in production. Always generate a unique value.
Google OAuth (Optional)
Auktiva supports Google OAuth for seamless sign-in. When enabled, users can sign up/login with their Google account.
Setting Up Google OAuth
- Go to Google Cloud ConsoleÂ
- Create a new project or select an existing one
- Navigate to APIs & Services â Credentials
- Click Create Credentials â OAuth client ID
- Select Web application as the application type
- Add authorized redirect URIs:
- Development:
http://localhost:3000/api/auth/callback/google - Production:
https://yourdomain.com/api/auth/callback/google
- Development:
- Copy the Client ID and Client Secret
Environment Variables
# Google OAuth credentials
GOOGLE_CLIENT_ID="your-google-client-id.apps.googleusercontent.com"
GOOGLE_CLIENT_SECRET="your-google-client-secret"Google OAuth is optional. If these variables are not set, the Google sign-in button will not appear on login/register pages.
How Google OAuth Works
- User clicks âContinue with Googleâ
- User authenticates with Google
- Auktiva receives user profile (email, name, avatar)
- If email exists â account is linked automatically
- If email is new â new user is created (no password required)
Account Linking
When a user signs in with Google:
- New email: Creates a new account with Google profile data
- Existing email: Links Google to the existing account
- Already linked: Signs in normally
Users can view their connected accounts in Settings â Connected Accounts.
Microsoft OAuth (Optional)
Auktiva supports Microsoft OAuth (Azure AD) for seamless sign-in with personal Microsoft accounts and work/school accounts.
Setting Up Microsoft OAuth
- Go to Azure PortalÂ
- Navigate to Azure Active Directory â App registrations â New registration
- Configure your app:
- Name: Your app name (e.g., âAuktivaâ)
- Supported account types: Select âAccounts in any organizational directory and personal Microsoft accountsâ
- Redirect URI: Select âWebâ platform
- Add redirect URIs:
- Development:
http://localhost:3000/api/auth/callback/azure-ad - Production:
https://yourdomain.com/api/auth/callback/azure-ad
- Development:
- After creation, copy the Application (client) ID
- Go to Certificates & secrets â New client secret
- Copy the secret Value (not the Secret ID)
Environment Variables
# Microsoft OAuth credentials
MICROSOFT_CLIENT_ID="your-application-client-id"
MICROSOFT_CLIENT_SECRET="your-client-secret-value"Microsoft OAuth is optional. If these variables are not set, the Microsoft sign-in button will not appear on login/register pages.
How Microsoft OAuth Works
- User clicks âContinue with Microsoftâ
- User authenticates with their Microsoft account
- Auktiva receives user profile (email, name, avatar)
- If email exists â account is linked automatically
- If email is new â new user is created (no password required)
How It Works
Registration (Email/Password)
- User submits email, name, and password
- Password is hashed using bcrypt (12 rounds)
- User record is created in the database
- User redirected to login
Registration (OAuth - Google/Microsoft)
- User clicks âContinue with Googleâ or âContinue with Microsoftâ
- Provider authenticates and returns profile
- User and Account records are created
- Session is created automatically
Login (Email/Password)
- User submits email and password
- Password is verified against stored hash
- JWT token is created
- Session cookie is set in browser
Login (OAuth - Google/Microsoft)
- User clicks OAuth provider button
- Provider authenticates user
- Account is verified/linked
- JWT token is created
Sessions
- Sessions use JWT strategy (token-based, not database-stored)
- JWT token is stored in an HTTP-only cookie
- Sessions expire after 30 days by default
Security Features
- Password hashing with bcrypt (12 rounds)
- CSRF protection via NextAuth
- HTTP-only cookies for JWT tokens
- JWT-based sessions for stateless authentication
Session Data
The session object contains:
{
user: {
id: string; // User's database ID
name: string; // User's display name
email: string; // User's email address
},
expires: string; // Session expiration date
}