Git Product home page Git Product logo

appwrite_auth_kit's Introduction

Appwrite Auth Kit

A Flutter wrapper for Appwrite's Accounts service, makes it easy to use manage authentication and account features.

Getting Started

This is really very easy to use

  1. Add dependency
dependencies:
    appwrite_auth_kit: <version>
  1. Wrap your MaterialApp AppwriteAuthKit passing a properly initialized Appwrite Client. Example below:
class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late Client client;
  @override
  void initState() {
    super.initState();
    //initialize your client
    client = Client();
    client
        .setEndpoint('https://localhost/v1')
        .setProject('60793ca4ce59e')
        .setSelfSigned();
  }

  @override
  Widget build(BuildContext context) {
    return AppwriteAuthKit(
      client: client,
      child: MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: MainScreen(),
      ),
    );
  }
}
  1. Access authNotifier from context. authNotifier is an instance of AuthNotifier that provides all the functions of Appwrite's Account service and some easy way to handle authentication.
  2. Get context.authNotifier.status gets the authentication status which can be one of the AuthStatus.uninitialized, AuthStatus.unauthenticated, AuthStatus.authenticating and AuthStatus.authenticated. You can check the status and display the appropriate UI, for example
class MainScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final authNotifier = context.authNotifier;

    Widget widget;
    switch (authNotifier.status) {
      case AuthStatus.authenticated:
        widget = AdminPage();
        break;
      case AuthStatus.unauthenticated:
      case AuthStatus.authenticating:
        widget = LoginPage();
        break;
      case AuthStatus.uninitialized:
      default:
        widget = LoadingPage();
        break;
    }
    return widget;
  }
}
  1. You must use the functions from the context.authNotifier instead default Account service from Appwrite SDK to create user, create session (login), delete session (logout), so that the context.authNotifier?.status is properly updated and your UI updates accordingly.

appwrite_auth_kit's People

Contributors

javibonilla avatar lohanidamodar avatar sbergmair avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.