@smiilliin/auth-api
TypeScript icon, indicating that this package has built-in type declarations

1.2.9 • Public • Published

auth-api - auth API

Usage

AuthAPI

Initialize AuthAPI class

const authAPI = new AuthAPI("https://smiilliin.com/api");

Load

Load fetchstrings

await authAPI.load("en");

login

Login with id and password

const refreshToken: string = await authAPI.login(id, password);
console.log("[Refresh Token]", refreshToken);

signup

Signup with id, password, google recaptcha response

const refreshToken: string = await authAPI.signup(id, password, g_response);
console.log("[Refresh Token]", refreshToken);

get access token

Get access token with refresh token

const accessToken: string = await authAPI.getAccessToken(refreshToken);
console.log("[Access Token]", accessToken);

renew refresh token

Renew refresh token

const renewedRefreshToken: string = await authAPI.renewRefreshToken(refreshToken);
console.log("[Refresh Token]", renewedRefreshToken);

TokenKeeper

const tokenKeeper = new TokenKeeper(authAPI, refreshToken, accessToken);

setTokenInterval

Set the interval between refresh callbacks

tokenKeeper.setTokenInterval(60 * 60 * 1000, 10 * 60 * 1000, 30 * 60 * 1000, 5 * 60 * 1000);

watchRefreshToken

Watch if the refresh token changed

tokenKeeper.watchRefreshToken = (refreshToken: string) => {
  console.log(refreshToken);
};

watchAccessToken

Watch if the access token changed

tokenKeeper.watchAccessToken = (accessToken: string) => {
  console.log(accessToken);
};

Package Sidebar

Install

npm i @smiilliin/auth-api

Weekly Downloads

0

Version

1.2.9

License

ISC

Unpacked Size

12.8 kB

Total Files

6

Last publish

Collaborators

  • smiilliin