-
Install the packages
npm i smol-auth-express -
Setup an env file with accessToken & RefreshToken secrets which are long strings. You can generate it by running the following commands:
node -e "console.log(require('crypto').randomBytes(32).toString('hex'));" -
Initialize smol service
import { validateUser, smol } from 'smol-auth-express'; import express from 'express'; const app = express(); const smolConfig = { connectionUrl: process.env.DB_URL, accessTokenSecret: process.env.ACCESS_TOKEN_SECRET, refreshTokenSecret: process.env.REFRESH_TOKEN_SECRET, clientDomain: process.env.WEBSITE_DOMAIN } smol() .init(app, smolConfig)
Only Express & postgreSQL (auth db) is supported
-
Basic Role: To grant broad permissions to a role, use the
*wildcard. For example:smol() .addRoles({ admin: '*', }, { defaultRole: 'admin' }) .init(app, smolConfig) -
Multiple & Specific Roles: To specify permissions for a role on a particular route and method, use an array. For example:
smol() .addRoles({ admin: '*', user: [{ route: '/posts', method: '*' }], viewer: [{ route: '/posts', method: ['GET'] }] }, { defaultRole: 'viewer' }) .init(app, smolConfig)
Default Role is required for now
-
Install the packages
npm i smol-auth-client -
Initialize smolClient
import { smolClient } from 'smol-auth-client' smolClient(process.env.API_DOMAIN) -
Use the corresponding functions
import { signin, signup, getAuthId, signout } from 'smol-auth-client' const signupData = await signup(email, password) const signinData = await signin(email, password) const authId = await getAuthId() await signout()
-
Clone the repo
git clone https://github.com/reenphygeorge/smol-auth -
Install all required packages
npm run install:all -
Build smol-packages
npm run build -
Start Example API Service
npm run start-example:api -
Start Example Client Service
npm run start-example:client -
Connect NocoDB to the auth db for dashboard
http://localhost:8080 -
To stop docker containers after exit
npm run docker:stop
