πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
Sign inDemoInstall
Socket

google-login-vue3

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-login-vue3

A lightweight and customizable Vue 3 component for Google OAuth 2.0 authentication, supporting both code-based and JWT-based authentication modes.

1.1.4
latest
Source
npm
Version published
Weekly downloads
6
-75%
Maintainers
1
Weekly downloads
Β 
Created
Source

Vue 3 Google Login Component

Login Demo

A lightweight and customizable Vue 3 component for Google OAuth 2.0 authentication supporting both JWT-based and Authorization Code-based flows.

🏠 Installation

npm install google-login-vue3

πŸš€ Usage

Import the component:

<template>
  <GoogleLogin
    :clientId="YOUR_GOOGLE_CLIENT_ID"
    mode="JWT"
    :oneTapLogin="true"
    @success="handleSuccess"
    @error="handleError"
  />
  <!-- Optional: mode="JWT" (default) or "code" -->
  <!-- Optional: Enables Google One Tap (:oneTapLogin="true") in JWT mode -->
</template>

<script setup>
import GoogleLogin from "google-login-vue3";

const handleSuccess = (response) => {
  console.log("Success response:", response);
  if (response.credential) {
    console.log("JWT Token:", response.credential);
    // Send the token to your backend for verification
  } else if (response.code) {
    console.log("Authorization Code:", response.code);
    // Send the code to your backend for access token exchange
  }
};

const handleError = (error) => {
  console.error("Google login error:", error);
};
</script>

Replace YOUR_GOOGLE_CLIENT_ID with your actual client ID from Google Developer Console.

πŸ” Authentication Modes

1. JWT-Based Authentication (ID Token Flow) [Default]

  • Google returns a JWT (ID Token) to the frontend.
  • No backend interaction is required (unless token validation is needed).
  • Ideal for apps using the ID token directly to verify identity.
  • One Tap Login is supported via the oneTapLogin prop.
  • Uses the native Google Sign-In button.

2. Code-Based Authentication (Authorization Code Flow)

  • Returns an Authorization Code to the frontend.
  • You must send this code to your backend to exchange for access/refresh tokens.
  • Best suited for secure OAuth flows requiring backend token handling.
  • Custom UI can be used via the default slot.

βš™οΈ Props

PropTypeDefaultDescription
clientIdStringβ€”Required. Your Google OAuth 2.0 client ID.
modeString"JWT""JWT" or "code" depending on the flow you want to use.
oneTapLoginBooleantrueEnables Google One Tap login (only valid in JWT mode).

🀩 Customization

  • In code mode, you can customize the login button using the default slot.

Example:

<GoogleLogin mode="code" :clientId="clientId">
  <template #default>
    <button class="my-custom-btn">Sign in with Google</button>
  </template>
</GoogleLogin>

πŸ”„ Backend Integration (For mode="code")

  • Use the authorization code to exchange tokens securely from your backend.
  • Recommended libraries:
    • Node.js: google-auth-library
    • Python: google-auth
  • Follow Google's OAuth 2.0 for Web Server Applications documentation.

⚠️ Notes

  • Configure JavaScript Origins and Redirect URIs in your Google Cloud Console.
  • For One Tap login, ensure the domain is verified.
  • Pop-up blockers can prevent login. Notify users if login fails due to browser settings.
  • Always handle success and error events properly.

🀝 Contributing

Contributions are welcome! Feel free to:

  • Open issues for bugs or feature requests.
  • Submit PRs to improve the codebase or docs.

πŸ“ License

MIT

πŸ‘¨β€πŸ’Ό Author

Shiv Baran Singh
πŸ“§ spyshiv@gmail.com
πŸ”— GitHub

Keywords

google-login-vue3

FAQs

Package last updated on 15 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts