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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@incrowd/auth-util

v2.2.0

Published

Generic authentication utility module

Readme

Generic Authentication Utility Module

A collection of JavaScript functions to handle authentication tasks such as sign up, sign in, and refresh access token.

Motivation

To reuse the same collection of authentication utility functions across all projects powered by FanScore.

Getting Started

npm i @incrowd/auth-util or yarn add @incrowd/auth-util

then in JavaScript:

import authUtil from '@incrowd/auth-util'
const config = {
    // Optional
    fetchStart: () => {
        // Logic to be called when fetch start
    },
    // Optional
    fetchEnd: () => {
        // Logic to be called when fetch end
    },
    authObj: () => {
        // return authObj
    },
    deviceId: () => {
        // return deviceId
    },
    clientId: () => {
        // return clientId
    },
    storeAuthObj: newAuthObj => {
        // Logic to store newAuthObj
    },
    baseUrl: {
        auth: () => {
            // return BASE_AUTH_API_URL
        },
        profile: () => {
            // return BASE_PROFILE_API_URL
        }
    }
}
const icAuth = authUtil(config)

API

simpleFetch (url, fetchStart = this.config.fetchStart, fetchEnd = this.config.fetchEnd)

icAuth.simpleFetch(url).then(r => {
    // Your logic to handle respond
})

Fetch from url using GET method without access token and return a Promise.


genericFetch (url, method, headers, body, fetchStart = this.config.fetchStart, fetchEnd = this.config.fetchEnd, tryAgain = false)

icAuth.genericFetch(url, 'POST', {
    'Content-Type': 'application/json'
}, body).then(r => {...})

Generic fetch method, mostly used by other methods within this library.


fetchWithAuth (url, method = 'GET', body, fetchStart, fetchEnd, token = this.config.authObj().access_token, tryAgain = true, language)

icAuth.fetchWithAuth(url).then(r => {...})

icAuth.fetchWithAuth(url, 'POST', {examplePayload: 'example'}).then(r => {...})

Fetch with access token and return a Promise. If fetch failed due to 401 Unauthorized, by default it will refreshToken and tryAgain once.


refreshToken ()

icAuth.refreshToken().then(r => {...})

Refresh access token, call storeAuthObj with newAuthObj and return a Promise.


getUser ()

icAuth.getUser()

Decode JWT token and return user object. null is returned if authentication object does not exist in store.


fetchOauth (body, fetchStart, fetchEnd)

icAuth.fetchOauth(bodyObj).then(r => {...})

Fetch with Content-Type being application/x-www-form-urlencoded and return a Promise. Normally will not call this function directly. This is used in login, register, and getAnonymousToken.


login (email, password, type = 'password', fetchStart, fetchEnd, organisation)

icAuth.login(email, password).then(r => {...})

Log in and return a Promise, the respond typically contains a new authentication object.


register (email, password, organisation, fetchStart, fetchEnd)

icAuth.register(email, password).then(r => {...})

Register and return a Promise, the respond typically contains a new authentication object.


getAnonymousToken (fetchStart, fetchEnd)

icAuth.getAnonymousToken().then(r => {...})

Return a Promise and the respond typically contains anonymous token.


convertBodyToFormData (body)

icAuth.convertBodyToFormData(bodyObj)

Normally will not call this function directly. This function will convert object key and value using encodeURIComponent.


resendVerifyEmail (fetchStart, fetchEnd)

icAuth.resendVerifyEmail().then(r => {...})

Resend verification email to current signed in user and return a Promise.


forgotPassword (email, fetchStart, fetchEnd)

icAuth.forgotPassword(email).then(r => {...})

Submit a reset password email request to the back end with email then return a Promise. User should then receive an reset password email allowing them to reset their password.


resetPassword (id, code, body, fetchStart, fetchEnd)

icAuth.resetPassword(usedId, resetPasswordCode, {newPassword}).then(r => {...})

Given the correct reset password code, submit body containing newPassword to reset password for user with given user id then return a Promise.


changePassword (body, fetchStart, fetchEnd)

icAuth.changePassword({oldPassword, newPassword}).then(r => {...})

Change user password with body object containing oldPassword and newPassword then return a Promise.


fetchProfile (fetchStart, fetchEnd)

icAuth.fetchProfile().then(r => {...})

Return a Promise, the respond typically contains a profile object.


updateProfile (body, method = 'PUT', fetchStart, fetchEnd)

icAuth.updateProfile({profilePicture, screenName, firstName, lastName}).then(r => {...})

Update user profile with body typically contains profilePicture, screenName, firstName, and lastName then return a Promise. profilePicture should be a string represents the image in base64 format without data:image/png;base64, in front. Default method is PUT which will replace the whole user profile, PATCH is also supported by the back end to update specific fields of the profile.


fetchContactPreferences (clientIds = ['INCROWD', this.config.clientId() || 'INCROWD'], fetchStart, fetchEnd)

icAuth.fetchContactPreferences().then(r => {...})

Return a Promise, the respond typically contains an array of contact preferences. Can pass in an array of client IDs, and duplication will be removed.


updateContactPreferences (body, clientId = this.config.clientId() || 'INCROWD', key = 'CLIENT', fetchStart, fetchEnd)

icAuth.updateContactPreferences({email: true, phone: false}).then(r => {...})

Update contact preferences for a given clientId. key can be "CLIENT", "SUPPORTED_CLUB", or "SPONSOR". The body typically contains email, sms, post, and phone, and they should all be Boolean.