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

@mccowngordon/vue-secure-token

v0.5.111

Published

## Description

Downloads

158

Readme

McCownGordon Construction Vue Secure Token

Description

Securely handles API authentication between Vue.js / Sharepoint Framework Extensions projects (SPFX) and Azure Functions using Active Directory Provider tokens.

  • Dynamically adds a vuex module to your store called SecureToken
  • Provides Vue.axios() and Vue.apiHandler() methods
  • Includes wrapper component <RenderComponent> that displays loading indicator and friendly error message

SecureToken store

| Getter | Description | | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | | sharepointContext | spfx this.context | | apiBaseUrl | Depending on the environment, for example: http://localhost:7071/api/RewardsRecognition or https://mgcforms.azurewebsites.net/api/RewardsRecognition | | environment | 'local' or 'production' | | token | jwt encoded token | | serverError | true or false - the apiHandler() method will update this if an error occurs | | unauthorized | true or false - the apiHandler() method will update this if the server returns a 401 response | | waitingOnServer | true or false - starts out as true and gets updated to false after apiHandler() method finishes with either status 200 or an error |

Setup

install:

    # NPM
    npm install @mccowngordon/vue-secure-token --save

Import the package:

In [projectName]WebParts.ts

import VueSecureToken, { VueSecureTokenConfig } from '@mccowngordon/vue-secure-token';

And initialize inside the render() method:

    const vueSecureTokenConfig: VueSecureTokenConfig = {
      store,
      spContext: this.context,
      localFunctionAppRoot: "http://localhost:7071/api/RewardsRecognition"
      azureFunctionAppRoot: "https://mgcforms.azurewebsites.net/api/RewardsRecognition"
    };
    Vue.use(VueSecureToken, vueSecureTokenConfig);

Update types in your project

types/vue/shims-vue.d.ts:

import { AxiosStatic } from "axios";
import { ApiHandler } from '@mccowngordon/vue-secure-token';

declare module 'vue/types/vue' {
    interface VueConstructor {
        axios: AxiosStatic,
        apiHandler: ApiHandler
    }
}

Usage

Anytime you want to call the MGC Function api:

// If first request is an error because of an expired token,
// retryFunc is called after retrieving a new valid token
const retryFunc = () => this.context.dispatch('fetchInitData');

Vue.apiHandler({
    method: 'get',
    url: 'giftsAndCards',
    waitingIndicator: true,
})
    .then((response) => {
        this.context.commit('SET_GIFTS_AND_CARDS', response.data);
    })
    .catch((err) => {
        if (err.message.includes(401)) {
            this.context.commit('SET_UNAUTHORIZED');
        } else {
            this.context.commit('SET_SERVER_ERROR');
        }
    });

How to use custom errors

if (typeof response === 'object' && response.toString().includes('403')) {
    // this is a forbidden response/error
    this.context.dispatch(
        'SecureToken/setCustomError',
        {
            set: true,
            message: 'Sorry you are not authorized to access this application.',
            type: 'Error',
        },
        {
            root: true,
        },
    );
} else {
    this.context.commit('SET_SUBMISSIONS', response.data);
    this.context.commit('SET_FETCHED');
    if (!this._statusFilter) {
        this.context.commit('SET_FILTER_SUBMISSIONS', this._filters[0]);
    }
    return true;
}

Display an error (from a Vue Component)

this.$store.dispatch(
    'SecureToken/setCustomError',
    {
        set: true,
        message: 'Error loading calendar.  Please contact the IT Department with this error message. 87400.',
        type: 'Error',
    },
    {
        root: true,
    },
);

Clear errors (from a Vue Component)

this.$store.dispatch(
    'SecureToken/setCustomError',
    {
        set: false,
        message: null,
        type: null,
    },
    {
        root: true,
    },
);

How to manually toggle the waiting indicator

  // loading indicator from separate module
  @secureToken.Action
  public setWaitingOnServer;


 this.setWaitingOnServer(true);

To Publish An Update

Currently this project is not in its own git repo. @TODO Save it as its own repo run npm run build ; npm publish