Using Built-in Authentication
Replyke’s built-in authentication makes it straightforward for developers to implement user sign-up, sign-in, and sign-out functionality in their applications. This is achieved through theuseAuth
hook. To interact with authentication features, use the useAuth
hook. It exposes several key functions and state properties:
Authentication State
TheuseAuth
hook provides access to the current authentication state:
loadingInitial
: Boolean indicating if the initial authentication state is still loadingaccessToken
: The current access token (null if not authenticated)refreshToken
: The current refresh token (null on desktop/web platforms, used for mobile authentication)setRefreshToken
: Function to manually set the refresh token (primarily for mobile platforms)
Authentication Functions
Sign-up
This function allows developers to create a new user account using an email and password. It also supports additional user attributes to provide a more personalized experience.Parameters:
Example:
Sign-in
This function handles user login using an email and password.Parameters:
Example:
Sign-out
This function signs out the currently authenticated user.Parameters:
Example:
Change-password
This function lets an authenticated user change their password.Parameters:
Example:
Request New Access Token
This function requests a new access token using the refresh token. It’s primarily used for mobile platforms where refresh tokens are stored securely. On desktop/web platforms, this function may not be needed as authentication uses cookies instead.Parameters:
Example:
Error Handling
All authentication functions throw errors when they fail. Make sure to wrap them in try-catch blocks:Summary
By leveraging these functions and state properties, developers can easily implement comprehensive authentication workflows in their projects. TheuseAuth
hook provides everything needed for user registration, authentication, password management, and token handling, enabling seamless integration into your application.