Skip to content

Account Helpers

This contains helpers for google.accounts namespace.

  • Type
function idRevoke(hint: string, callback?: RevocationCallback): void;
  • Details

This idRevoke provides a helper to access google.accounts.id.revoke method. It revokes the OAuth grant used to share the ID token for the specified user.

  • Example
import { idRevoke } from "vue3-google-signin";
idRevoke("1618033988749895", (done) => {
console.log(done.error);
});
  • Type
function decodeCredential(credential: string): DecodedGoogleUser;
  • Details

Helper method to decode the JWT token retrieved from the GoogleSignIn onSuccess response into a usable Object

Google returns a jwt token encoded using base64url. This method will help you get a typed object to manipulate the data for your application.

  • Example
<script setup lang="ts">
import {
GoogleSignInButton,
decodeCredential,
type CredentialResponse,
type CredentialSuccessResponse,
} from "vue3-google-signin";
const handleSignInSuccess = ({ credential }: CredentialSuccessResponse) => {
const user = decodeCredential(credential);
console.log("User:", user);
};
const handleSignInError = (response: CredentialResponse) => {
console.error("Google returned no credential", response);
};
</script>
<template>
<GoogleSignInButton
@success="handleSignInSuccess"
@error="handleSignInError"
/>
</template>

Output:

{
"email": "user@example.com", // The user's email address
"email_verified": true, // true, if Google has verified the email address
"hd": "example.com", // If present, the host domain of the user's GSuite email address
"name": "John Smith",
"family_name": "Smith",
"given_name": "John",
"id": "3141592653589793238", // The unique ID of the user's Google Account
"picture": "https://lh3.googleusercontent.com/a-/e2718281828459045235360uler",
"iat": 1590000000, // The time the ID token was issued, in seconds since the Unix epoch
"exp": 1590003600, // The time the ID token expires, in seconds since the Unix epoch
}