Auth

auth({ get?, login?, register? })

noonjs uses a default authentication mechanism based on username and password for registration and login. You can easily change the username field to a cellphone number or any other identifier. If you need to completely replace the authentication logic, you can use the provided method to do so.

import Noonjs from "noonjs" 
import config from "../config.json"

const noonjs = new Noonjs(config)
    
noonjs.auth({
    get(req) {

        // return user profile details
    },
    login(req) {

        // find user

        return { access: { _id, permissions } }
        // return { access: { _id, permissions }, refresh: { _id } }
    },
    register(req) {

        // create user

        return { access: { _id, permissions } }
        // return { access: { _id, permissions }, refresh: { _id } }
    }
})

noonjs.start()

In noonjs, the login and register methods should either throw an error or return an object containing the access token, which includes necessary details. noonjs will generate a signed token for you based on your security key. If you also return a refresh token, noonjs will use it to generate additional access tokens and maintain the user's authentication state.

Edit this page on Github
© 2025 kav3.com. Crafted with and dedication.