Quick Start
A working example is available in our github examples repo.This guide assumes you are using Typescript. Please adjust the snippets as needed to remove the types if you are using plain JS.
If you plan to use Web3 features, select “Auth + Web3” from the tabs below.
- Auth
- Auth + Web3
App.ts
Usage
The User Button
The Civic Auth SDK comes with a multi-purpose styled component called theUserButton
- Auth
- Auth + Web3
TitleBar.ts

The user button
Customizing the User Button
You can customize the styling of the user button by adding either aclassName or style property to the UserButton component when declaring it. These styling properties affect both the sign-in button and the user information display when logged in. For further customization, you can also style the buttons that appear in the dropdown menu (which displays when clicking on the user information button) by using the dropdownButtonClassName or dropdownButtonStyle properties. This gives you granular control over both the main user button and its associated dropdown menu items. Using a className:
- Auth
- Auth + Web3
style.css
CustomUserButtonClassName.ts
!important directive i.e. using just the classname in App.css would not work:
- Auth
- Auth + Web3
CustomUserButtonStyles.ts
style and className props, where the value in style will always take precedence over the same CSS-defined style.
Getting User Information on the Frontend
Use the Civic Auth SDK to retrieve user information on the frontend.- Auth
- Auth + Web3
MyComponent.ts
onSignIn and onSignOut callbacks to the useUser hook to trigger actions when the user signs in or out:
- Auth
- Auth + Web3
MyComponent.ts
We use
name as an example here, but you can call any user object property from the user fields schema, as shown below.Creating your own Login and Logout buttons
You can use thesignIn() and signOut() methods from the useUser() hook to create your own buttons for user log in and log out
- Auth
- Auth + Web3
RollYourOwnLogin.ts
Advanced Configuration
Civic Auth is a “low-code” solution, so all configuration takes place via the dashboard. Changes you make there will be updated automatically in your integration without any code changes. The only required parameter you need to provide is the client ID. The integration provides additional run-time settings and hooks that you can use to customize the library’s integration with your own app. If you need any of these, you can add them to the CivicAuthProvider as follows:Display Mode
The display mode indicates where the Civic login UI will be displayed. The following display modes are supported:-
iframe(default): the UI loads in an iframe that shows in an overlay on top of the existing page content -
redirect: the UI redirects the current URL to a Civic login screen, then redirects back to your site when login is complete -
new_tab: the UI opens in a new tab or popup window (depending on browser preferences), and after login is complete, the tab or popup closes to return the user to your site
Redirecting Users After Login
Important: The
loginSuccessUrl configuration parameter is not supported for React or other frontend-only Single Page Applications (SPAs).Since we don’t know whether you want to use client-side routing (and which router library you’re using) or perform a full page redirect, you should handle post-login navigation using the onSignIn hook.API
User Context
The full user context object (provided byuseUser) looks like this:
AuthStatus
TheauthStatus field exposed in the UserContext can be used to update your UI depending on the user’s authentication status, i.e. update the UI to show a loader while the user is in the process of authenticating or signing out.
User
TheUser object looks like this:
Base User Fields
Token Fields
Typically developers will not need to interact with the token fields, which are used only for advanced use cases.
Verifying tokens on your backend:When sending the access token from your frontend to your backend for verification, you can access it from the To verify the token signature on your backend, use the For complete backend verification examples and details, see the
userContext object:@civic/auth-verify library which automatically queries the Civic JWKS endpoint to fetch the public key:@civic/auth-verify documentation.Forwarded Tokens
Use forwardedTokens if you need to make requests to the source provider, such as find out provider-specific information. An example would be, if a user logged in via Google, using the Google forwarded token to query the Google Groups that the user is a member of. For example:Embedded Login Iframe
If you want to have the Login screen open directly on a page without the user having to click on button, you can import theCivicAuthIframeContainer component along with the AuthProvider option iframeMode={"embedded"}
You just need to ensure that the CivicAuthIframeContainer is a child under a CivicAuthProvider
- Auth
- Auth + Web3
App.ts

