3.0.1 • Published 4 years ago

@sheetbase/auth v3.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

@sheetbase/auth

User management system for Sheetbase app.

  • Install: npm install --save @sheetbase/auth

  • Usage:

// 1. import module
import { AuthModule } from "@sheetbase/auth";

// 2. create an instance
export class App {
  // the object
  authModule: AuthModule;

  // initiate the instance
  constructor() {
    this.authModule = new AuthModule(/* options */);
  }
}
NameTypeDescription
encryptionSecretstring
oobBody?OobBody
oobSubject?OobSubject
oobUrl?string | OobUrl

The Lib class.

NameTypeDescription
authActionRouteAuthActionRoute
authOauthRouteAuthOauthRoute
authOobRouteAuthOobRoute
authPublicRouteAuthPublicRoute
authRouteAuthRoute
authServiceAuthService
authTokenRouteAuthTokenRoute
authUserRouteAuthUserRoute
helperServiceHelperService
idTokenMiddlewareIdTokenMiddleware
oauthServiceOauthService
oobServiceOobService
optionServiceOptionService
tokenServiceTokenService
userMiddlewareUserMiddleware
FunctionReturns typeDescription
registerRoutes(routeEnabling?, middlewares?)RouterService<>Expose the module routes
useUserMiddleware()RoutingHandler
userIdTokenMiddleware()RoutingHandler

Expose the module routes

Parameters

ParamTypeDescription
routeEnablingtrue | DisabledRoutes
middlewaresMiddlewares | RouteMiddlewares

Returns

RouterService<>


The useUserMiddleware call signature.

Returns

RoutingHandler


The userIdTokenMiddleware call signature.

Returns

RoutingHandler


AuthModule provides REST API endpoints allowing clients to access server resources. Theses enpoints are not exposed by default, to expose the endpoints:

AuthModule.registerRoutes(routeEnabling?);

AuthModule returns these routing errors, you may use the error code to customize the message:

  • auth/invalid-email: Invalid email.
  • auth/invalid-input: Invalid input.
  • auth/invalid-password: Invalid password.
  • auth/invalid-token: Invalid token.
  • auth/user-exists: User already exists.
  • auth/user-not-exists: No user.
RouteMethodDisabledDescription
/auth/actionGETtrueDefault oob ui
/auth/actionPOSTtrueHandle for oob action
/auth/oauthGETtrueGet oauth user profile
/auth/oobGETtrueCheck an oob code
/auth/oobPOSTtrueHandle oob actions
/auth/oobPUTtrueSend oob emails
/auth/publicGETtrueGet user public profiles
/authDELETEtrueLogout or delete account
/authPOSTtrueLog a user in
/authPUTtrueCreate new account
/auth/tokenGETtrueexchange the refresh token for a new id token
/auth/userGETtrueGet auth user profile
/auth/userPATCHtrueUpdate auth user data

DISABLED Default oob ui

Request query

NameTypeDescription
modestring
oobCodestring

Response

string


DISABLED Handle for oob action

Request body

NameTypeDescription
modestring
oobCodestring
newPassword?string

Response

object


DISABLED Get oauth user profile

Request query

NameTypeDescription
providerIdUserProviderId
accessTokenstring

Response

object


DISABLED Check an oob code

Request query

NameTypeDescription
oobCodestring
modestring

Response

object


DISABLED Handle oob actions

Request body

NameTypeDescription
oobCodestring
modestring
newPassword?string

Response

void


DISABLED Send oob emails

Request body

NameTypeDescription
modestring
emailstring

Response

void


DISABLED Get user public profiles

Request query

NameTypeDescription
uid?string
uids?string

Response

UserProfile | object


DISABLED Logout or delete account

Request body

NameTypeDescription
cancelAccount?boolean
refreshToken?string

Middleware data

NameTypeDescription
userUserObject

Response

void


DISABLED Log a user in

Request body

NameTypeDescription
email?string
password?string
customToken?string
offlineAccess?boolean

Response

Record<string, unknown>


DISABLED Create new account

Request body

NameTypeDescription
email?string
password?string

Response

object


DISABLED exchange the refresh token for a new id token

Request query

NameTypeDescription
refreshTokenstring

Response

object


DISABLED Get auth user profile

Middleware data

NameTypeDescription
userUserObject

Response

UserInfo


DISABLED Update auth user data

Request body

NameTypeDescription
profile?UserEditableProfile
additionalData?Record<string, unknown>
settings?Record<string, unknown>
publicly?string[
]
privately?string[
]
username?string
currentPassword?string
newPassword?string

Middleware data

NameTypeDescription
userUserObject

Response

UserInfo


License

@sheetbase/auth is released under the MIT license.