Authentication
Complete guide to authentication in ShopySeed — email/password, OAuth, email verification, password reset, and session management.
Authentication
ShopySeed provides a complete authentication system out of the box, including email/password login, Google OAuth, email verification, and password reset.
Authentication Flow
Registration
- User submits email and password at
/auth/register - Backend creates the user with a hashed password (bcrypt)
- A verification email is sent with a unique token
- User is logged in immediately with a JWT + refresh token
Login
- User submits email and password at
/auth/login - Backend validates credentials and returns JWT + refresh token
- Tokens are stored as HTTP-only cookies
- Frontend redirects to
/dashboard
Session Management
- Access token: Short-lived JWT (15 minutes)
- Refresh token: Long-lived token stored in database (7 days)
- Automatic token refresh on 401 responses via the
fetchApiwrapper
Google OAuth
ShopySeed supports Google OAuth login out of the box.
Setup
- Create a Google OAuth app in the Google Cloud Console
- Set the redirect URI to:
{API_URL}/auth/oauth/google/callback - Add your credentials to
.env:
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secretFlow
- User clicks "Continue with Google" on the login/register page
- Frontend redirects to
/auth/oauth/google(a loading page) - Browser redirects to the backend OAuth endpoint
- Backend handles the Google callback, creates/links the user
- User is redirected back to the frontend with tokens set
Email Verification
After registration, users receive a verification email with a unique token link.
- Endpoint:
POST /auth/resend-verification— resend the verification email - Rate limit: 1 email per hour
- Token expiry: 24 hours
- Verification page:
/auth/verify-email/[token]
Unverified users see a banner on the dashboard with a "Resend email" button.
Password Reset
Forgot Password Flow
- User enters their email at
/auth/forgot-password - Backend sends a reset email with a unique token (1 hour expiry)
- User clicks the link →
/auth/reset-password?token=... - User sets a new password
- All existing refresh tokens are invalidated
Endpoints
POST /auth/forgot-password— request a reset emailPOST /auth/reset-password— reset password with token
API Endpoints
| Method | Endpoint | Description |
|---|---|---|
POST | /auth/register | Create a new account |
POST | /auth/login | Login with email/password |
POST | /auth/refresh | Refresh access token |
POST | /auth/logout | Invalidate refresh token |
GET | /auth/me | Get current user profile |
PATCH | /auth/me | Update profile (name) |
POST | /auth/avatar | Upload profile picture |
POST | /auth/forgot-password | Request password reset |
POST | /auth/reset-password | Reset password with token |
POST | /auth/resend-verification | Resend verification email |
GET | /auth/verify-email/:token | Verify email address |
GET | /auth/oauth/google | Initiate Google OAuth |
Security
- Passwords are hashed with bcrypt (10 rounds)
- JWT tokens use RS256 or HS256 signing
- Refresh tokens are stored in database and invalidated on logout
- Rate limiting on auth endpoints prevents brute force
- HTTP-only cookies prevent XSS token theft