Skip to content

Get Started

vue3-google-signin wraps Google Identity Services (GIS), the library behind Sign in with Google. It gives you Google’s button as a Vue component, and One Tap and the two OAuth2 flows as composables. It works in any Vue 3 app, and in Nuxt 3 and 4 through the nuxt-vue3-google-signin module.

You want to Use You get
Sign users in GoogleSignInButton An ID token that says who the user is
Sign users in without a trip to a login page useOneTap An ID token
Sign users in with a button in your own design useTokenClient or useCodeClient An access token or a code
Read the user’s Calendar, Drive, … in the browser useTokenClient An access token that lasts about an hour
Call Google APIs from your server useCodeClient A code your server exchanges for tokens

Each row links to its guide. Whichever you pick, the steps below are the same.

  1. Open Credentials in the Google Cloud console, and pick or create a project. If the console asks you to configure the consent screen first, give it your app’s name and a support email.

  2. Click Create credentials > OAuth client ID and choose Web application.

  3. Under Authorized JavaScript origins, add every origin your app runs on, with its port. For local development add both http://localhost and the dev server’s origin: http://localhost:5173 for Vite, http://localhost:3000 for Nuxt.

  4. Copy the client ID. It ends in .apps.googleusercontent.com. It isn’t a secret: it ships to the browser.

Install the package with your package manager:

Terminal window
npm install vue3-google-signin

Register the plugin in your entry point. Keep the client ID in an environment variable so each environment can use its own:

src/main.ts
import { createApp } from "vue";
import GoogleSignInPlugin from "vue3-google-signin";
import App from "./App.vue";
createApp(App)
.use(GoogleSignInPlugin, {
clientId: import.meta.env.VITE_GOOGLE_CLIENT_ID,
})
.mount("#app");
.env
VITE_GOOGLE_CLIENT_ID=1234567890-abc.apps.googleusercontent.com
src/components/SignIn.vue
<script setup lang="ts">
import {
GoogleSignInButton,
type CredentialSuccessResponse,
} from "vue3-google-signin";
const onSuccess = ({ credential }: CredentialSuccessResponse) => {
// An ID token (JWT). Send it to your server and verify it there.
console.log(credential);
};
</script>
<template>
<GoogleSignInButton @success="onSuccess" />
</template>

The plugin also registers GoogleSignInButton globally, so the import is only there for your editor.

Start your dev server and open the page. Google draws its button; sign in and the ID token shows up in the console.