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

@cory-clearing/vue-google-login

v2.0.7

Published

Button to login with google with really simple setup

Downloads

32

Readme

vue-google-login

Button to login with google with really simple setup

Installation

To use the login and logout buttons there is no installation needed, just import and use.

If you want to have access to the auth api then you need add the plugin.

2.0.5 update

Added callback to get the current user without adding the plugin (Thanks rmoscuba)

2.0.1 update

Added support to Edge (Thanks Magyarb)

Added option to render a sign-in button with google UI (Thanks TheTrueRandom)

2.0.0 update

Added support for the full auth api configuration.

Props

    // The Google Sign-In params configuration object. Required.
    // https://developers.google.com/identity/sign-in/web/reference#gapiauth2clientconfig    
    params: Object
    // It gets called if the action (login/logout) is successful.
    onSuccess: Function
    // It gets called if the action (login/logout) fails.
    onFailure: Function
    // It determines if the button is for logging in or for logging out.
    // By default is false so you only need to add it for the logout button
    logoutButton: Boolean
    // Optional, if provided will call gapi.signin2.render with the provided params and render a button with google UI
    // https://developers.google.com/identity/sign-in/web/reference#gapisignin2renderid-options
    renderParams: Object
    // If you are logged in it will return the current user when the component mounts
    // The object it's the same as onSuccess
    onCurrentUser: Function

Usage

    // It can also be imported as { GoogleLogin }
    import GoogleLogin from 'vue-google-login';

    // Button to login
    <GoogleLogin :params="params" :onSuccess="onSuccess" :onFailure="onFailure">Login</GoogleLogin>

alt text

    // Button to login with google ui rendered using the renderParams object
    // The rendered button can't be use to logout since it is rendered by the google api and will only login
    // If you add the logoutButton param to true it will show a normal button without styles
    <GoogleLogin :params="params" :renderParams="renderParams" :onSuccess="onSuccess" :onFailure="onFailure"></GoogleLogin>

alt text

    // Button to logout
    <GoogleLogin :params="params" :logoutButton=true>Logout</GoogleLogin>
    export default {
        name: 'App',
        data() {
            return {
                // client_id is the only required property but you can add several more params, full list down bellow on the Auth api section
                params: {
                    client_id: "xxxxxx"
                },
                // only needed if you want to render the button with the google ui
                renderParams: {
                    width: 250,
                    height: 50,
                    longtitle: true
                }
            }
        },
        components: {
            GoogleLogin
        }
    }

There is no need to add callbacks to the logout button since the api doesn't return anything, you can do it nonetheless to make sure it worked.

When the user successfully signs in, the callback will return an object that contains a lot of information about the user and about the access token granted.

    methods: {
        onSuccess(googleUser) {
            console.log(googleUser);

            // This only gets the user information: id, name, imageUrl and email
            console.log(googleUser.getBasicProfile());
        }
    }

Styling the buttons

Even if it is a component you can think about it as a button, you can add classes, inline styles, etc...

Without renderParams is a button, with renderParams is a div since google injects the button so take it into account when adding styles to the component.

Auth api

This is completely optional. It's just to have access to the Auth api. It is not needed to use the buttons.

First import the plugin

    import { LoaderPlugin } from 'vue-google-login';

Then add the plugin to the Vue instance with the params, client_id is the only property required but you can add some optional.


    Vue.use(LoaderPlugin, {
        client_id: CLIENT_ID
    });

Full list of params

Then you will have access to the auth api. It comes as a promise because the script doesn't load instantly. This way we avoid having to worry about if the script has loaded yet or not.

    Vue.GoogleAuth.then(auth2 => {
        console.log(auth2.isSignedIn.get());
        console.log(auth2.currentUser.get())
    })

Full auth api methods