1.1.0 • Published 3 years ago
mushroomjs-auth v1.1.0
Install
npm install mushroomjs-authOr
yarn add mushroomjs-authDependent on
mushroomjsImport
import mushroom from "mushroomjs-auth";Or
import mushroom from "mushroomjs";
import "mushroomjs-auth";Usage
Login
const remember = true; // true - no expired, false - will auto expired after token_time_to_live minute(s) inactive
const token = await mushroom.$auth.loginAsync("your account", "your password", remember);See more about token_time_to_live
Logout
// invalid session at this device of client
await mushroom.$auth.logoutAsync({ mode: LogoutMode.InvalidClientSession });
// invalid session at this device of client and other devices of client that use the same token (shared token)
await mushroom.$auth.logoutAsync({ mode: LogoutMode.invalidServerSession });
// invalid all sessions of user
await mushroom.$auth.logoutAsync({ mode: LogoutMode.invalidServerSession });Status
const status = await mushroom.$auth.statusAsync();Me
const me = await mushroom.$auth.meAsync();Register
const result = await mushroom.$auth.registerAsync("your account", "your password");Activate
await mushroom.$auth.activateAsync("your account", "activation code");Recover password
await mushroom.$auth.recoverPasswordAsync("your account");Reset password
await mushroom.$auth.resetPasswordAsync("your account", "your code", "your new password");Change password
await mushroom.$auth.changePasswordAsync("your account", "your old password", "your new password")Events
mushroom._on("$auth.ready", () => { /* handle ready event here */ });
mushroom._on("$auth.loggedin", () => { /* handle loggedin event here */ });
mushroom._on("$auth.loggedout", () => { /* handle loggedout event here */ });State
mushroom.$auth.isReady will be true right before ready event is fired
Manually set token
const permanent = true; // true - no expired, false - will auto expired after token_time_to_live minute(s) inactive
await mushroom.$auth.setTokenAync("your token", permanent);Settings
auth.token_time_to_live
Settings the number of minute(s) that token will be expired after inactive (when parameter remember is false in loginAsync method).
mushroom.$setting.set("auth.token_time_to_live", 5); // default is 30 minutesOverride
To override the built-in methods above, define your custom methods like:
import mushroom, { createRestfulAsyncFunction } from "mushroomjs";
mushroom.$auth.registerAsync = (account, password, type) => createRestfulAsyncFunction<RegisterResponse>({
name: "$auth.register", // Identify your method
method: "POST",
blankBody: false,
url: mushroom.using() + "custom register url"
})({ user: account, pwd: password, type, x: 1, y: 2 });Release notes
1.1.0
New features:
- Support TypeScript
- Compatible with
mushroomjs@1.1.* - Add setting
auth.token_time_to_live
1.1.0
3 years ago
1.1.0-alpha.7
3 years ago
1.1.0-alpha.5
4 years ago
1.1.0-alpha.6
4 years ago
1.1.0-alpha.4
4 years ago
1.1.0-alpha.3
5 years ago
1.1.0-alpha.1
5 years ago
1.1.0-alpha.2
5 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago