user_auth

Dart - Backend user auth helpe, with common methods

Pub Example

Show some :heart: and star the repo

Fork Star Watch

usage

  • import package:user_auth/user_auth.dart.
  • create instance from UserAuth.
  • init with apiBaseUrl and other parameters.

methods

  • login : waits for user in response to return.
  • check : waits for user in response to return.
  • logout : return true | false.
  • loadUser : return user if stored in prefs.
  • register : waits for user in response to return.

example

import 'package:user_auth/user_auth.dart';

// instance
UserAuth user = new UserAuth();

// init
SharedPreferences prefs = await SharedPreferences.getInstance();
  await user.init(
    apiBaseUrl: 'https://example.com/api',
    store: true,
    prefs: prefs, // need if store: true
    loginUrl: "/user/login",
    registerUrl: "/user/register",
    checkUrl: "/user/details",
    logoutUrl: "/user/logout",
  );

// Note : change 'Bearer ' and api_token with your own parameters

// login
var activeUser = loadedUser = await user.login(
                    usernameVar: 'email',
                    usernameVal: 'test@test.com',
                    password: '12345678',
                  );

// check
var checkedUser = await user.check(
                    type: 'Bearer ',
                    token: activeUser['api_token'],
                  ); 

// logout
var logout = await user.logout(
                    type: 'Bearer ',
                    token: activeUser['api_token'],
                  );

// register
Map form = {
            "email" : "test@test.com",
            "phone" : "00000000",
            "name" : "mohamed sayed",
            "password" : "1234567",
            };
registeredUser = await user.register(form: form);

Project Created & Maintained By

Mohamed Sayed

Software Engineer | In :heart: with Flutter

Donate

If you found this project helpful or you learned something from the source code and want to thank me, consider buying me a cup of :coffee:

Note : All Contibutions Are Welcomed

Libraries

user_auth