useAuthStateuseGuestState
useAuthState()
This hook is used to verify that a user is authenticated. If the user is not authenticated, they will be redirected to the login page. If the user is authenticated, this hook will return an object containing the user, tokens and their setters as well as alogout() function.
useAuthState hook also returns setUser, setToken and setRefreshToken functions that can be used to update the user’s information.
useGuestState()
This hook is used to verify that a user is unauthenticated. If the user is authenticated, they will be redirected to the home page. If the user is unauthenticated, this hook will return an object containing alogin() function. This function takes in an object containing the user and tokens and sets them in the appropriate storage.
useLogin
AlthoughuseGuestState provides a login() function, it is not always convenient to use it. For example, if you have a complex authentication sytem, you might want to be able to login from other components. For this, Hana Auth provides a useLogin hook that can be used to login a user.
login() function in the example above will automatically redirect the user to the home page after they have been logged in. If you however have an operation that you want to perform after the user has been logged in, you can usethe login() function as a promise. You can also pass in a redirect option to the login() function to make sure the redirect does not happen.
useLogout
This hook is used to logout a user. It clears the user and tokens from the appropriate storage and redirects the user to the login page.logout() function in the example above will automatically redirect the user to the login page after they have been logged out. If you however have an operation that you want to perform after the user has been logged out, you can usethe logout() function as a promise. You can also pass in a redirect option to the logout() function to make sure the redirect does not happen.
useUser
This hook is used to get the user’s information. It returns the user’s information if the user is authenticated. The returned object contains the user, tokens and their setters.getAuth
You might be in a situation where you need to get the user’s information outside of a component. For example, you might need to get the user’s information or tokens in a utility function. For this, Hana Auth provides agetAuth function that can be used to get the user’s information.

