Account Helpers
This contains helpers for google.accounts
namespace.
idRevoke()
- Type
ts
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
ts
import { idRevoke } from "vue3-google-signin"
idRevoke('1618033988749895', done => {
console.log(done.error);
})
- See More: Docs
decodeCredential()
- Type
ts
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.
INFO
This is not an official method exposed by google
- Example
vue
<script setup lang="ts">
import type { CredentialResponse } from "vue3-google-signin";
import { GoogleSignInButton, decodeCredential } from "vue3-google-signin";
const handleSignInSuccess = (response: CredentialResponse) => {
const { credential } = response;
const decodedCredential = decodeCredential(credential);
console.log("User:", decodedCredential);
};
const handleSignInError = () => {
console.error("Signin Failed");
};
</script>
<template>
<GoogleSignInButton
@success="handleSignInSuccess"
@error="handleSignInError"
/>
</template>
Output:
json
{
"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
}