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

@studytweaks/vuejs-user

v0.1.7

Published

Vuejs user plugin

Downloads

3

Readme

Vuejs user

Installation

via npm

npm install @studytweaks/vuejs-user

via yarn

yarn add @studytweaks/vuejs-user

Usage

Provided components are built on Buefy so install buefy first from there official site

For Font Awesome icons, add following to <head> :

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

Install Vuejs user module as follows:

# main.js

import userPlugin from '@studytweaks/vuejs-user'

import Profile from './models/Profile'
import User from './models/User'

let apiRoutes = {
  login: '/login',
  logout: '/logout',
  profile: '/profile',
  refresh: '/login/refresh'
}

let routes = {
  login: 'login',
  logout: 'login', // route to go after logout
  profile: 'profile'
}

// key is credential param used by user plugin, value is param needed by backend
let credentialsParamMapper = {
  username: 'email'
}

let profileModel = new Profile()
let userModel = new User()

Vue.use(
  userPlugin,
  {
    apiRoutes,
    axios,
    credentialsParamMapper,
    profileModel,
    redirectRoute: 'login',
    router,
    routes,
    store,
    userModel,
    vueAuthenticateOptions,
  }
)

Options

| Option | Description | Type | Default Value | |:-----------------------|:----------------------------------------------|:---------|:--------------------| | apiRoutes | API endpoints related to user authentication | Object | | | axios | The instance of axios used by app | Object | | | credentialsParamMapper | Overridden credential keys to API keys mapper | Object | | | loginRouteName | The name of the login route | String | 'login' | | profileModel | The stub instance of profile model | Object | StudytweaksProfile object | | redirectAfterLogout | The name of the route to redirect to after user logs out | String | 'home' | | router | The registered router instance | Object | | | store | The Vuex store to use | Object | | | userModel | The stub instance of user model | Object | StudytweaksUser object | | vueAuthenticateOptions | Social login provider options | Object | |

Note: routes option can have logout key whose value does not refer route of logout. It refers the route to go after logout.

Route meta fields

This plugin uses following meta fields in beforeEach guard of router instance. These can be specified when defining a route in the app

| Meta field key | Description | Type | Value | |:-----------------|:----------------------------------------------------------------------------------|:--------|:-------| | redirectOnExpire | Redirect to redirectRoute when both access token and refresh token gets expired | Boolean | true | | requiresAuth | Make route accessible to only authenticated user. Redirects to redirectRoute when user is not logged in. | Boolean | true |

Social login

For social login, install and setup vue-authenticate in your app as follows:

# main.js

let vueAuthenticateOptions = {
  baseUrl: process.env.API_BASE_URL, // API domain

  providers: {
    facebook: {
      clientId: process.env.FACEBOOK_CLIENT_ID,
      redirectUri: window.location.origin + '/'
    },
    github: {
      clientId: process.env.GITHUB_CLIENT_ID,
      redirectUri: window.location.origin
    },
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID,
      redirectUri: window.location.origin
    },
    linkedin: {
      clientId: process.env.LINKEDIN_CLIENT_ID,
      redirectUri: window.location.origin
    }
  }
}

Vue.use(User, { store, router, redirectRoute: 'login', userEndpoints, vueAuthenticateOptions, axios })

Configure client ID of each platform that you want to enable on config/{environment}.env.js of your app.

Then you can render login component with various social login links by passing respective prop as follows:

<studytweaks-login facebook github google linkedin></studytweaks-login>

For login form on modal dialog

When mounting component if refresh token is expired(with Vue.$studytweaksAuth.isRefreshExpired()) or on axios request if error occurs with 401 Unauthorized status, you can authenticate using studytweaks-login component as modal body inside your modal.

You can set no-redirect prop to remain on current page after logging through modal dialog. You can listen to login:success event and handle closing modal dialog, re-requesting endpoint etc. on your event handler.

<studytweaks-login @login:success="hideLoginModal" no-redirect></studytweaks-login>

Component Reference

<studytweaks-login>

Properties

| Property | Description | Type | Default Value | |:------------|:--------------------------------------|:--------|:----------------------------------| | facebook | Facebook login button | Boolean | false | | github | Github login button | Boolean | false | | google | Google login button | Boolean | false | | linkedin | Linkedin login button | Boolean | false | | | redirect | Route to redirect to after login. false for no redirect. | 'Boolean|String|Object' | 'home' | | title | Title to show as heading | String | translated user.login.title key |

Events

| Event | Description | |:--------------|:-----------------------------------| | login:error | emits after error while logging in | | login:start | emits before invoking login | | login:success | emits after successful login |

<studytweaks-profile>

Properties

| Property | Description | Type | Default Value | |:------------|:-----------------------------------------|:--------|:--------------| | update-url | API route to update current user profile | String | |

Events

| Event | Description | |:-------------------|:-------------------------------------------------------| | before-update | emits before invoking update | | unauthorized-error | emits if response status is 401 while refreshing token | | update-error | emits after error while updating profile | | update-success | emits after successful profile update |

<studytweaks-user-menu>

Properties

| Property | Description | Type | Default Value | |:---------|:-------------------------------|:---------------|:-----------------------------------| | divider | Show dropdown divider | Boolean | true | | login | Login route | Object, String | 'login' | | profile | Profile route | Object, String | | | right | Right align dowpdown menu | Boolean | false | | signup | Signup route | Object, String | 'signup' | | welcome | Content to show on menu button | String | translated user.menu.welcome key |