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

nuxt-simple-auth

v1.4.5

Published

Authentication module simple for Nuxt.js

Downloads

36

Readme

Static Badge Static Badge npm version GitHub License npm downloads Nuxt Static Badge

Installation

nuxt-simple-auth is a feature-rich open source authentication module for Nuxt3 applications.

Quick Start

npm i nuxt-simple-auth pinia @pinia/nuxt
yarn add nuxt-simple-auth pinia @pinia/nuxt

Setup

Installation

Then, add nuxt-simple-auth to the modules section of nuxt.config.js:

Config

nuxt.config.js

{
     modules: [
        'nuxt-simple-auth',
        '@pinia/nuxt'
    ],
  
    auth: {
  
    }
},

Strategies

 strategies: {
        local: {
            redirect: {
               logout: "/logout"
            },
            token: {
                property: 'access_token',
            },
            user: {
                property: 'profile',
            },
            endpoints: {
                login: {url: '/oauth/token', method: 'post'},
                user: {url: '/api/profile', method: 'get'},
                "2fa": {url: '/api/token_2fa', method: 'post'},
                logout: false,
            },
        },
    }

Cookie

prefix - Default token prefix used in constructing a key for token storage. options - Additional cookie options, passed to cookie path - path where the cookie is visible. The default is '/'. expires - can be used to specify the lifetime of the cookie in Number of Days or Specific Date. The default is session only. maxAge - Specifies the number (in seconds) that will be the Max-Age value (preferably expired) domain - domain (and by extension subdomain(s)) where the cookie is visible. The default is domain and all subdomains. secure - defines whether the cookie requires a secure protocol (https). Default is false, should be set to true if possible.

Note: By default, the prefix on localhost is set to "auth." __Secure- prefix: Cookies with names starting with __Secure- (dash is part of the prefix) must be set with the secure flag from a secure page (HTTPS). __Host- prefix: Cookies with names starting with __Host- must be set with the secure flag, must be from a secure page (HTTPS), must not have a domain specified (and therefore, are not sent to subdomains), and the path must be /.

cookie: {
        options: {
            httpOnly: true,
                secure: true,
                sameSite: 'Lax',
                priority: 'high',
            //maxAge: 24 * 60 * 60 * 1000,
        },
        prefix: '__Secure-auth.',
    }

2fa

Two-factor identification The 2fa token will have all settings already defined in the cookie default: false

"2fa":  true,

Pages

    definePageMeta({
      middleware: ['auth', '_2fa']
    });

runtimeConfig

**nuxt.config.js **

secret:{
    strategyName:{
        grant_type: 'password',
         client_id: 0,
         client_secret: '',
    }
}

 public: {
     apiBase: '/api',
     baseURL: process.env.baseURL,
 }
        

Methods

loginWith(strategyName, ...args)

Return: Promise

Set the current strategy as strategyName and attempt to log in. The usage may vary based on the current strategy.

const {$auth} = useNuxtApp()

$auth.loginWith('local', data)
      .then(response => {
        
      })
logout(strategyName)

Set the current strategy as strategyName and logout, ensuring the destruction of Pinia's cookies and state.

const {$auth} = useNuxtApp()

$auth.logout(strategyName)
_2fa(strategyName, ...args)

Return: Promise

Set the current strategy as strategyName and attempt to validate the code with a simplified two-factor authentication ( 2FA) and the creation of cookies with HttpOnly. The utilization of these features varies based on the current strategy.

$auth._2fa('local', data).then(response => {

})
 const {data, pending, error, refresh} = useFetch(url, {
    $fetch: useRequestFetch(),
    headers: $auth.$headers,
  })
 $auth.$headers.set('name', 'value ')
 $auth.$headers.get('name', 'value ')

⚖️ License

Released under MIT by @4slan.