Integrate Civic Auth into your Vanilla JavaScript application with just a few lines of code.
http://localhost:3000
for development)main.js
):YOUR_CLIENT_ID
with your actual client ID and you’re done.
loginUrl
option:
backendEndpoints
configuration is only used when loginUrl
is provided. Each endpoint is optional - if not
specified, the default will be used.Field | Required | Default | Description |
---|---|---|---|
clientId | Yes | - | Your Civic Auth client ID from auth.civic.com |
targetContainerElement | No | - | DOM element where embedded iframe will be rendered |
redirectUrl | No | Current URL | OAuth redirect URL after authentication |
displayMode | No | modal | How the auth UI is displayed: embedded , modal , redirect , or new_tab |
scopes | No | ['openid', 'profile', 'email'] | OAuth scopes to request |
loginUrl | No | - | Backend URL for login redirect (enables backend integration) |
backendEndpoints | No | See below | Custom backend API endpoints (only used with loginUrl ) |
loginUrl
for backend integration, the following default endpoints are used:
displayMode
option controls how the authentication UI is presented:
embedded
(default): The auth UI loads in an iframe within your specified container elementmodal
: The auth UI opens in a modal overlay on top of your current pageredirect
: Full page navigation to the Civic auth server and back to your sitenew_tab
: Opens auth flow in a new browser tab/popup windowauthClient.getCurrentUser()
to retrieve current user information before logoutauthClient.isAuthenticated()
to check if user is currently logged inFailed to resolve module specifier "@civic/auth/vanillajs"
, this is typically caused by a corrupted module cache or installation issue.
Solution:
@civic/auth
package or when the package installation is interrupted.
startAuthentication()
getCurrentUser()
isAuthenticated()
logout()