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

@roadiz/nuxt-realm

v0.3.0

Published

Roadiz realm authentication with Nuxt

Downloads

11

Readme

nuxt-realm

Roadiz realm authentication with Nuxt

Usage

yarn add @roadiz/nuxt-realm

Configuration

Add module in you nuxt.config.js file

// nuxt.config.js
buildModules: [
    '@roadiz/nuxt-realm'
]

Bearer authentication

This module use Nuxt auth module https://auth.nuxtjs.org for bearer authentication.
$auth is automatically injected by this module, and it'll be used for handling user authentication.
It must be installed and setup before using it.

yarn add --exact @nuxtjs/auth-next
yarn add @nuxtjs/axios
// nuxt.config.js
{
    modules: [
        '@nuxtjs/axios',
        '@nuxtjs/auth-next'
    ], 
    auth: {
        strategies: {
            roadiz: {
                provider: require.resolve('./node_modules/@roadiz/nuxt-realm/dist/auth-provider.js'), 
                baseURL: 'https://api.example.com' // optional
            }
        },
        // i18n (optional)
        plugins: [require.resolve('./node_modules/@roadiz/nuxt-realm/dist/auth-i18n.js')]
    }
}

The RoadizRealm component

The module comes with a built-in component <RoadizRealm> for display a Roadiz realm.
It's a renderless component, it can wrap only one root component.

<template>
    <roadiz-realm :response="myRoadizWebResponse">
      <div> // or any other tag / component
        // ... 
      </div>
    </roadiz-realm>
</template>

This component provides methods and properties for handling realm state.

export interface RoadizRealmProvide {
    realm?: RoadizSecureRealm // active realm
    realmAuthWithPassword(password: string): Promise<void> // authenticate with password
    realmHasPassword(): boolean // is there already a filled password for this realm
    realmIsBearerScheme: boolean // bearer authentication scheme 
    realmIsPasswordScheme: boolean // plain password authentication scheme 
    realmIsAuthenticated(): boolean // is the current realm already authenticated (with user for bearer scheme or password for password scheme) 
}

These methods and properties can be injected into any child component.

Active realm

export default Vue.extend({
    inject: ['realm'],
})

Testing authentication scheme

<template>
    <login-form v-if="realmIsBearerScheme && !$auth.loggedIn" />
</template>
export default Vue.extend({
    inject: ['realmIsBearerScheme'],
})

Authenticate with plain password (password scheme)

<template>
    <form @submit="submit">
      <input type="password" v-model="password" />
      // ...
    </form>
</template>
export default Vue.extend({
    inject: ['realmAuthWithPassword'],
    data() {
        return {
            password: ''
        }
    },
    methods: {
        submit(event: Event) {
            event.preventDefault()
            
            this.realmAuthWithPassword(this.password)
        }
    }
})

Testing if active realm has a stored password

<template>
    <password-form v-if="!hasPassword" />
</template>
export default Vue.extend({
    inject: ['realmHasPassword'],

    computed: {
        hasPassword(): boolean {
            return this.realmHasPassword() // use a computed prop with a getter for using data reactivity
        }
    }
})

Authenticate with user (bearer scheme)

<template>
    <form @submit="submit">
      <input type="username" v-model="login.username" />
      <input type="password" v-model="login.password" />
      // ...
    </form>
</template>
export default Vue.extend({
    data() {
        return {
            login: {
                username: '',
                password: ''
            }
        }
    },
    methods: {
        submit(event: Event) {
            event.preventDefault()

            this.$auth.loginWith('roadiz', { data: this.login })
        }
    }
})