user_auth 1.2.2 user_auth: ^1.2.2 copied to clipboard
Dart - Backend user auth helpe, with common methods like login and register
user_auth #
Dart - Backend user auth helpe, with common methods
Show some ❤️ and star the repo #
usage #
- import
package:user_auth/user_auth.dart
. - create instance from
UserAuth
. - init with
apiBaseUrl
and other parameters.
methods #
login
: waits foruser
in response to return.check
: waits foruser
in response to return.logout
: returntrue
|false
.loadUser
: returnuser
if stored in prefs.register
: waits foruser
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 #
#
Software Engineer | In ❤️ 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 ☕