[Flutter] Katana Auth

Hello. My name is Masaru Hirose.

Here are some of the packages that will be used for the comprehensive framework that will be released later.

This time, the package will be around authentication.

This is a testing package for later use of Firebase Authentication.

I’ve put together some instructions on how to use it, so if you’re interested, go ahead and give it a try!


Base package to facilitate switching between Local and Firebase authentication implementations.


FirebaseAuthentication for use around authentication is useful.

Various types of authentication can be easily implemented, including authentication by e-mail address, phone number, and SNS accounts.

However, even if Firebase authentication is to be used later, there may be times when you want to implement authentication without connecting to the server when creating a mockup of the application, or when you want to implement authentication in the test code.

Therefore, I have implemented a package that allows switching between Firebase and local authentication using an adapter, just as I did with katana_model.

In addition, the interface has been improved so that it is easy to switch between using Google sign-in and Apple sign-in depending on the application.


Import the following packages.

flutter pub add katana_auth

If you use Firestore, import the following packages together.

flutter pub add katana_auth_firebase


Advance preparation

Always place the AuthAdapterScope widget near the root of the app.

Pass an AuthAdapter such as RuntimeAuthAdapter as the adapter parameter.

// main.dart
import 'package:flutter/material.dart';
import 'package:katana_auth/katana_auth.dart';

void main() {
  runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  Widget build(BuildContext context) {
    return AuthAdapterScope(
      adapter: const RuntimeAuthAdapter(),
      child: MaterialApp(
        home: const AuthPage(),
        title: "Flutter Demo",
        theme: ThemeData(
          primarySwatch: Colors.blue,

Creating Authentication Objects

To perform authentication, first create an Authentication and keep it somewhere.

The Authentication object can obtain the following data to check the status of authentication.

  • isSignedIn:Returns true if authenticated.
  • isAnonymously:Returns true for anonymous authentication.
  • userId:Returns the user ID.
  • userEmail:Returns the user's email address if email authentication, etc. is performed.
  • userPhoneNumber:Returns the user's phone number if phone number verification is performed.

In addition, since Authentication inherits ChangeNotifier, it is possible to monitor updates by using addListener or riverpod's ChangeNotifierProvider, for example.

// auth_page.dart
import 'package:flutter/material.dart';
import 'package:katana_auth/katana_auth.dart';

class AuthPage extends StatefulWidget {
  const AuthPage({super.key});

  State<StatefulWidget> createState() => AuthPageState();

class AuthPageState extends State<AuthPage> {
  final auth = Authentication();

  void initState() {

  void _handledOnUpdate() {
    setState(() {});

  void dispose() {

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("App Demo")),
      body: ListView(
        children: [
            title: Text("SignedIn: ${auth.isSignedIn}"),
            title: Text("Anonymously: ${auth.isAnonymously}"),
            title: Text("ID: ${auth.userId}"),
            title: Text("Email: ${auth.userEmail}"),
            title: Text("Phone: ${auth.userPhoneNumber}"),

User Registration & Login

The auth.register method is used to register users.

RegisterAuthProvider must be passed as the argument.

RegisterAuthProvider should be obtained using an AuthQuery with a register method.

(AuthQuery is discussed below.)

await auth.register(
    email: "[email protected]",
    password: "12345678",

Also, use auth.signIn to perform login.

The SignInAuthProvider must be passed as an argument and should be obtained using an AuthQuery with a signIn method.

await auth.signIn(
    email: "[email protected]",
    password: "12345678",

Use auth.confirmSignIn to confirm authentication, such as to perform mail link authentication or SMS authentication.

await auth.confirmSignIn(
    code: "012345",

Change User Information

Use auth.change to change user information.

ChangeAuthProvider is passed as an argument, but the AuthQuery method can be changed depending on what is to be changed.

  • EmailAndPasswordAuthQuery.changeEmail:Change of e-mail address.
  • EmailAndPasswordAuthQuery.changePassword:Change password.
  • SmsAuthQuery.changePhoneNumber:Change of telephone number.
await auth.change(
    email: "[email protected]"

(Only available when logged in.)


Use auth.signOut to log out.

Available only at login, no arguments required.

await auth.signOut();


It is possible to change the authentication system by passing it when defining the AuthAdapterScope.

  • RuntimeAuthAdapter:Authentication system that works only when the app is launched. Authentication information is reset when the app is re-launched. Use this system when testing.
  • LocalAuthAdapter:Authentication system that works only locally on the device. Authentication information remains even if the application is re-launched, but cannot be shared among other devices.
  • FirebaseAuthAdapter:FirebaseAuthentication system. Allows sharing of authentication information between terminals; requires initial Firebase configuration.


AuthQuery is provided for each authentication provider.

By using the AuthQuery method, it is possible to use the functions for authentication provided by the Authentication class.

(Availability is limited by the authentication provider.)

  • AnonymouslyAuthQuery:AuthQuery for providers offering anonymous authentication.
  • EmailAndPasswordAuthQuery:AuthQuery for providers that offers authentication by email address and password.
  • EmailLinkAuthQuery:AuthQuery for providers that offers authentication via email link.
  • SmsAuthQuery:AuthQuery for providers offering authentication via SMS.
  • SnsSignInAuthProvider:Abstract class of AuthQuery for providers offering authentication with SNS accounts. Since it is an abstract class, the actual AuthQuery can be used by loading other related packages.


I made it for my own use, but if you think it fits your implementation philosophy, by all means, use it!

Also, I releasing the source here, so issues and PullRequests are welcome!

If you have any further work requests, please contact me directly through my Twitter or website!

Offers app development and apps using Flutter and Unity. Includes information on music and videos created by the company. Distribution of images and video materials. We also accept orders for work.

GitHub Sponsors

Sponsors are always welcome. Thank you for your support!

Developed the katana/masamune framework, which has dramatically improved the overall efficiency of Flutter-based application development.