SDK/User Loading States
Overview
Before using the SDK through hooks etc., you need to ensure that it has loaded. In addition, you might also want to wait for a user to have logged in to call certain hooks.
This guide will show you how to check if the SDK has loaded and how to handle the different loading states for the login process.
Wait for SDK to load (variable)
The sdkHasLoaded variable is available from the useDynamicContext hook and can be used to check if the SDK has loaded.
Check if user is logged in (hook)
The useisloggedin hook will tell you if the user has finished the whole onboarding process i.e. they signed in/up and completed any required information capture.
Note that Dynamic has two modes for a user to be in: connect-only and connect-and-sign (learn more here). In connect-only mode, the user is considered logged in once they have connected their wallet(s) and in connect-and-sign mode, the user is considered logged in once they have connected their wallet(s) and signed a message.
useIsLoggedIn will return true for connect-only when a wallet is connected but there is no UserActivation, and for connect-and-sign when a wallet is connected and a valid user is present.
Check if user is authenticated but hasn’t finished onboarding
useIsLoggedIn tells you if the user has finished the whole onboarding process, but if you want to know if the user has authenticated but hasn’t finished the process, you can use [userWithMissingInfo] from the useDynamicContext hook.
This will be undefined if the user is not authenticated or if they have finished the onboarding process and will contain the user object otherwise. Conversely, the user object from the same hook will be defined if the user is authenticated and has finished the onboarding process.
Access user during login (handler)
The handleAuthenticatedUser handler is a handler that can be used to intercept the workflow once a user has been authenticated but before the auth process completes and we close the UI.
It gives you a UserProfile object for the given user.
Check when login has started (callback)
The onAuthInit callback gives you information about a login process that has just begun.
Check out the full reference for the return value (args).
Check when authentication has completed (callback)
The onAuthSuccess callback runs once the user has authenticated and is signed in (i.e. completed any mandatory info capture & MFA).
Check out the full reference for the return value (args).
Check if login failed (callback)
There are two callbacks which you can use for this:
- The onAuthFailure callback will be called when an authentication process fails, either by error or user closing the modal.
- The onAuthCancel callback will be called specifically if the modal is closed before login is completed, it is not called on error.
Was this page helpful?