Comment on page
Custom authentication allows you to manage auth-related data (login details) while utilizing your own backend to authenticate users.
Let's see how to add custom authentication by building an example that looks like this:
The steps to add custom authentication are as follows:
To enable custom authentication in FlutterFlow:
- 1.Open Setting and Integrations () > App Settings > Authentication.
- 2.Turn on the Enable Authentication toggle and set Authentication Type to Custom.
- 4.By default, the Persist Auth Sessions option is enabled, which means users remain logged in until they actively log out. With this option enabled, your app will automatically open to the homepage whenever it's restarted.
- 5.After successful authentication, your backend typically sends login details like an authentication token, a refresh token, and user details. To keep the user logged in within your app, you must store this data. You can achieve this by enabling Associate User Data Type and setting User Data Type to the custom Data Type. Note that the structure of your custom Data Type should closely resemble the structure of a successful authentication's JSON response. At the very least, it should include critical fields like the authentication token.
Let's add a page that allows users to create accounts and log in. To speed up, you can add a page from the template. Here is the page added from the templates, and after some modification, it looks the below:
After successful authentication, you can save the auth related data using the 'Log in' action. Here's how you do it:
- 2.Under the User Auth Properties, you can set values for Authentication Token, Refresh Token, Token Expiry Time, and User UID. Note that for the 'Persist Auth Sessions' option to work, you must set the Authentication Token.
To access the auth data after a user logs in, open the set from variable menu > Authenticated User > choose from Auth Properties or User Data Fields.
Logout a user
Published Date: November 2, 2023