Skip to main content

Handling Auth Deep Links

In many authentication flows/operations, Altogic redirects your user to a specific URL.

For example, oAuth2 flow after the user signed in with the provider sign-in page, Altogic redirects the user to the redirect URL you specified in the Altogic Designer.

You can use deep linking in mobile or desktop applications to open the application from a redirect URL.

Deep Linking Configuration

Deep linking uses a domain with a custom scheme (like altogic:// to open an application with the link.

To configure deep linking for your application, you need to add a custom scheme to your application.


<activity android:name=".MainActivity">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="altogic" android:host=""/>

In this example, your mobile app will open when altogic:// is launched in the mobile browser.

Handling Redirect URL

By getting the link that opens the application, perform the following action in the authentication flow.


AltogicState listens to initial links automatically in the mobile application. If the application is launched with a link, AltogicState will handle the link, and you can perform the following action in the authentication flow with redirect.

void main() {

class AltogicAuthExampleApp extends StatefulWidget {
const AltogicAuthExampleApp({Key? key}) : super(key: key);

State<AltogicAuthExampleApp> createState() => _AltogicAuthExampleAppState();

class _AltogicAuthExampleAppState extends AltogicState<AltogicAuthExampleApp> {

void onEmailVerificationLink(BuildContext? context, EmailVerificationRedirect redirect) {
// Handle email verification link

void onMagicLink(BuildContext? context, MagicLinkRedirect redirect) {
// Handle magic link

void onOauthProviderLink(BuildContext? context, OauthRedirect redirect) {
// Handle oAuth2 provider link

void onEmailChangeLink(BuildContext? context, ChangeEmailRedirect redirect) {
// Handle email change link

void onPasswordResetLink(BuildContext? context, PasswordResetRedirect redirect) {
// Handle password reset link

Widget build(BuildContext context) {
return MaterialApp(
navigatorObservers: [navigatorObserver],

/// ...

If you want to use BuildContext in the methods, you need to add navigatorObserver to navigatorObservers of MaterialApp (or WidgetsApp etc.).


Generally, in the first run of the application, many developers show a splash screen. In this case, the application is launched with a deep link, AuthState.onX methods triggered, and maybe the user navigated to another page from the method. Also, the splash screen will try to navigate to another page. This case causes a conflict.

To avoid this conflict, you can use AltogicState.applicationInitialRedirect static getter:

Future<void> init() async {
// Check if the application was launched with a deep link before navigate from the splash screen
var launchedRedirect = await AltogicState.applicationInitialRedirect;
if (launchedRedirect != null) {

Handling Errors

If an error occurs during authentication flow, Altogic redirects the user to the redirect url with error query parameter.

Perform Action

After getting the redirect link (or Redirect instance in Flutter), you can perform the following action in the authentication flow.

On magic-link, email-confirm, oauth-signinthe next action is to sign in with the user with getAuthGrant.

On email-change there isn't necessary action.

On reset-pwd next action is to reset the password with resetPasswordWithToken.