Overview
YBH Pulse Content uses email/password authentication with JWT-based sessions, restricted to@popularit.net email addresses for internal team access.
Authentication Flow
User signs in with email and password
Email domain validation ensures only
@popularit.net accounts can authenticate.JWT token is generated and set as HTTP-only cookie
Token includes user ID, email, and role for authorization.
User Roles
Role-based access control (RBAC) determines what actions users can perform:- Admin
- Designer
- User
Full access to all features:
- Create, edit, and delete episodes
- Generate and approve content
- Manage visual assets
- Create and manage users
- Configure system settings
- Access analytics and reports
Session Management
Session cookies
Authentication tokens are stored as HTTP-only cookies:Security features:
HttpOnlyprevents JavaScript access to prevent XSS attacksSecureensures cookies only sent over HTTPSSameSite=Laxprovides CSRF protectionMax-Age=86400sets 24-hour expiration
JWT payload
Tokens include:Session expiration
Sessions expire after 24 hours. Users are automatically redirected to the login page when:- Token has expired
- Token signature is invalid
- User has been deactivated
Rate Limiting
Login attempts are rate-limited to prevent brute force attacks:Password Requirements
Passwords must meet these criteria:- Minimum 8 characters
- At least one uppercase letter
- At least one lowercase letter
- At least one number
- At least one special character (!@#$%^&*)
Passwords are hashed using Argon2id (memory-hard algorithm resistant to GPU cracking) before storage in Sanity.
Password Reset
Users can reset forgotten passwords via email:Email configuration
Password reset emails require environment variables:User Management
Creating users
Admins can create new users from Settings > Team:- Click Add Team Member
- Enter name and email (
@popularit.netonly) - Set initial password (user can change later)
- Assign role (Admin, Designer, User)
- Click Create User
Creating the first admin
Use the CLI script to create the initial admin account:Updating user roles
Admins can change user roles:- Navigate to Settings > Team
- Find user in the list
- Click Edit
- Select new role from dropdown
- Click Save
Deactivating users
Deactivate users to revoke access without deleting data:- Go to Settings > Team
- Find user to deactivate
- Click Deactivate
- Confirm action
- Cannot sign in
- Existing sessions immediately invalidated
- Content created by user remains intact
- Can be reactivated later
Public Access
Guest brand kit pages
Share links (/share/:token) are publicly accessible without authentication:
- No login required to view brand kits
- Tokens are cryptographically secure (random 32-byte strings)
- Tokens don’t expire (permanent share links)
- Access tracked with view counts and analytics
Share links are safe to send to external guests. They only expose approved content for a specific episode.
Gallery pages
Public gallery pages (/gallery/:uuid) display episode assets:
- Optional feature for showcasing work
- UUID generated per episode
- Controlled visibility via episode settings
API Authentication
Internal API endpoints require valid JWT tokens:Protected endpoints
Token validation
API routes validate tokens from cookies:Authorization checks
Role-based checks for sensitive operations:Environment Setup
Required secrets
Set these environment variables in Cloudflare Pages:Local development
Create.dev.vars for local development:
Troubleshooting
”Invalid credentials” error
Check:- Email address ends with
@popularit.net - Password is correct (case-sensitive)
- Account is not deactivated
- Caps Lock is off
”Too many login attempts” error
Wait 15 minutes before trying again, or:- Try from a different network
- Contact admin to reset rate limit manually
Session expires immediately
Verify:JWT_SECRETis set correctly in production- System clock is synchronized (JWT uses timestamps)
- Browser accepts cookies (check privacy settings)
Password reset email not received
Check:- Email in spam/junk folder
RESEND_API_KEYis validRESEND_FROM_EMAILis configured- Email domain is verified in Resend dashboard