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

@service-paradis/vue-firebase-auth

v0.0.3

Published

Vue Authentication with Firebase.

Downloads

2

Readme

Vue Firebase Auth

A simple light-weight authentication library for Vue.

Installation

npm install @service-paradis/vue-firebase-auth

Usage

Basic Configuration

import FirebaseAuth from '@service-paradis/vue-firebase-auth'

Vue.use(FirebaseAuth, {
    project: {
        apiKey: '<API_KEY>',
        authDomain: '<PROJECT_ID>.firebaseapp.com',
        databaseURL: 'https://<DATABASE_NAME>.firebaseio.com',
        storageBucket: '<BUCKET>.appspot.com',
        messagingSenderId: '<SENDER_ID>',
        projectId: '<PROJECT_ID>',
    }
})

Using Options

Available option (all optional)

authRedirect: '/login'
  • Redirect to use if authentication is required on a route. // TODO other options

Usage

const router = new VueRouter();
Vue.use(FirebaseAuth, {
    project: {
        // ...
    },
    options: {
        authRedirect: '/auth/login'
    }
})

// TODO other options

Using VueRouter

This plugin works with the vue-router plugin. Setting an auth meta field in the router mapping section will ensure authenticated access to that route.

Usage

const router = new VueRouter();
Vue.use(FirebaseAuth, {
    project: {
        // ...
    },
    router
})

Routing meta

auth: true
  • User must be authenticated.
auth: false
  • If the user is logged in, this route will be unavailable. Useful for login/register pages to be unaccessible once the user is logged in.
auth: undefined
  • Public, no checks required.
authRedirect: String

Each route can define it's own specific redirect. NOTE: If not set it will default to the global redirect options.

// TODO roles? Inspiration from https://raw.githubusercontent.com/websanova/vue-auth/master/docs/Privileges.md // TODO usage example

// TODO explain that $firebaseAuth will be available everywhere

Available Methods

user

  • Returns the current user or null if there is not.

Usage

<div>
    {{ $firebaseAuth.user().displayName }}
</div>

check

  • Check to see if the user is logged in. // TODO roles as argument?
<router-link v-if="!$firebaseAuth.check()"
             :to="'/login'">
    login
</router-link>
<a v-if="$firebaseAuth.check()"
   @:click="$firebaseAuth.logout()">
    logout
</a>

register

  • Will register user using Firebase Authentication with email and password.
  • Required parameters: email and password
  • Accepts redirect parameter which is passed directly to router when registration is successful. (default to '/') // TODO other types
const { email, password } = this;
this.$firebaseAuth.register({ email, password })
    .then((user) => {
        console.log('User created successfully:', user);
        // You can create user related record in database here
    }).catch((error) => {
        console.error('Registration Failed:', error);
        // Handle error here
    });

login

  • Will login user using Firebase Authentication with email and password.
  • Required parameters: email and password
  • Accepts redirect parameter which is passed directly to router when login is successful. (default to '/') // TODO other types
const { email, password } = this;
this.$firebaseAuth.login({ email, password })
    .then((user) => {
        console.log('User logged in successfully:', user);
        // Some actions on login here
    }).catch((error) => {
        console.error('Login Failed:', error);
        // Handle error here
    });

logout

  • Will logout user using Firebase.
  • Accepts redirect parameter which is passed directly to router when logout is successful. (default to authRedirect option)
this.$firebaseAuth.logout({ redirect = '/signed-out' })
    .then(() => {
        console.log('User logged out successfully.');
        // Some actions on logout here
    }).catch((error) => {
        console.error('Logout Failed:', error);
        // Should not happen, but handle potential error here
    });

WIP (Coming soon)

  • Available Methods
    • ready()?
    • check() to improve with roles checking
    • token()?
    • fetch()?
    • refresh()?
  • Different types for register/login (Google, Facebook, etc.)
  • router meta management for role?
  • Axios Interceptors
    • retrieve received new token when available on response
    • insert token on every request
  • Password reset management?

// TODO split documentation into separate section (files)