npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@trixcms/nauth

v1.0.21

Published

NAuth is an library for using custom auth between nodejs and TrixCMS. (For exemple : For your modded minecraft project...)

Downloads

4

Readme

NAuth

NAuth is a library to authenticate users of your TrixCMS site in NodeJS.

Prerequisites

Before using NAuth you must install the Auth plugin on your CMS

Installation

You can install the library via npm:

npm install @trixcms/nauth

How to use ?

First you need to define an instance of NAuth. The manufacturer will take the URL of your TrixCMS site as the first parameter and an optional second parameter, a timeout in milliseconds:

const NAuth = require('@trixcms/nauth')

const auth = new NAuth('http://website.domain')

Verify that a user exist

You can verify that a user exists with the exists (username: string): Promise <boolean> method which will take the username as a parameter. The method will return a promise to you.

const username = 'username'

auth.exists(username)
    .then((exists) => {

        if(exists) {
            console.log('The account exists.')
        } else {
            console.log('The account does not exists.')
        }

    })
    .catch(() => {
        console.error('An error has occurred.')
    })

Retrieve user information

You can verify that a user exists with the login (username: string, password: string): Promise <Profile> method which will take the username and password as parameters. The method will return you a promise with the profile:

const username = 'username'
const password = 'password'

auth.login(username, password)
    .then((profile) => {
        console.log(profile);
    })
    .catch(err => {
        if(err.code === 'INVALID_CREDENTIALS') {
            console.error('Bad credentials')
        } else {
            console.error('An error has occurred.')
        }
    })

List of properties available in the profile:

| Property | Type | Description | | ----------- | -------------- | --------------------------------------------- | | id | string | The user ID. | | uuid | string | User UUID. | | username | string | Username of the user. | | email | string | User email address. | | money | number | Number of user store points. | | hasAvatar | boolean | Does the user have an avatar. | | isBanned | boolean | Is the user banned. | | banReason | string | null | The reason for the ban if the user is banned. | | isConfirmed | boolean | Has the user confirmed their email address. | | hasTwoAuth | boolean | Has the user enabled dual authentication. | | ranks | string[] | List of user ranks. | | token | string | User token. | | createdAt | Date | Date of creation of the account. | | updatedAt | Date | Date of last modification of the account. |

Code example

const NAuth = require('@trixcms/nauth')

// We create an instance of NAuth
const auth = new NAuth('https://example.domain/', 10000)

// We verify that the 'admin' account exists.
auth.exists('admin')
    .then((exists) => {
        if (exists) {
            // The 'admin' account exists!

            // We retrieve the account profile using the login method.
            auth.login('admin', '123456789')
                .then((profile) => {

                    // optional
                    if (profile.isBanned) {
                        // This account is banned
                        return console.log('This account is banned')
                    }

                    // optional
                    if (!profile.isConfirmed) {
                        // This account has not validated its email address.
                        return console.log('This account has not validated its email address.')
                    }

                    // You can retrieve account information:
                    const uuid = profile.uuid
                    const username = profile.username
                    const email = profile.email
                    const token = profile.token

                    console.log('Here is the information about the admin account:', uuid, username, email, token)
                })
                .catch((err) => {
                    if (err.code === 'INVALID_CREDENTIALS') {
                        // Account credentials are invalid.
                        console.log('Account credentials are invalid.')
                    } else {
                        // An error has occurred.
                        console.log('An error has occurred.')
                    }
                })
        } else {
            // The 'admin' account does not exist!
            console.log('This account does not exist')
        }
    })
    .catch(() => {
        console.log('An error has occurred.')
    })

GitHub code size in bytes GitHub issues GitHub pull requests NPM GitHub package.json version