1. Install dependencies
2. Configure your App
Minimal Configuration
3. Set up CORS (for frontend integration)
If your frontend runs on a different domain/port, configure CORS to enable cross-origin cookie sharing:secure: true + sameSite: "none" for cross-origin compatibility. Without HTTPS, cross-origin cookies will not be saved by the browser.
4. Set up Cookies
Civic Auth uses cookies for storing the login state by default5. Create a Login Endpoint
This endpoint will handle login requests, build the Civic login URL and redirect the user to it.6. Create the Callback Endpoint
This endpoint handles successful logins and creates the session7. Create a Logout Endpoint
This endpoint will handle logout requests, build the Civic logout URL and redirect the user to it.8. Add Middleware
Middleware protects routes that require login.9. Use the Session
If needed, get the logged-in user information.10. Frontend Integration (Vanilla JavaScript)
Use the@civic/auth/vanillajs client with your backend:
Advanced Configuration
For more advanced use cases, you can include additional optional parameters in your configuration:| Parameter | Required | Description |
|---|---|---|
clientId | Yes | Client ID from auth.civic.com |
redirectUrl | Yes | OAuth 2.0 callback URL - The backend endpoint where Civic redirects after authentication to complete the token exchange (e.g., https://your-backend.com/auth/callback). This URL must be registered in your Civic Auth dashboard under “Domains”. |
postLogoutRedirectUrl | No | Where to redirect users after logout |
loginSuccessUrl | No | Post-authentication redirect - After your backend completes authentication, redirect the user to this URL (typically your frontend). Use this when your frontend (SPA) calls your backend to initiate login. If not set, the callback endpoint will return a success response instead of redirecting. |
oauthServer | No | OAuth server URL (useful for development/testing environments) |
PKCE and Client Secrets
Civic Auth supports multiple OAuth 2.0 authentication methods to provide maximum security for different application architectures.Need client secret authentication? Civic Auth supports PKCE-only, client secrets, and hybrid PKCE + client secret approaches. See our Authentication Flows guide for detailed comparison.

