UNPKG

vue3-google-signin

Version:

Google Sign-in for Vue3 with Google Identity Service

81 lines (80 loc) 2.63 kB
import type { CodeResponse, CodeClientConfig } from '../interfaces/oauth2'; import { type Ref } from "vue"; import type { MaybeRef } from '../utils/types'; /** * On success with implicit flow */ export type ImplicitFlowSuccessResponse = Omit<CodeResponse, "error" | "error_description" | "error_uri">; /** * On error with implicit flow */ export type ImplicitFlowErrorResponse = Pick<CodeResponse, "error" | "error_description" | "error_uri">; /** * Options for Implicit flow * * @export * @interface ImplicitFlowOptions * @extends {(Omit<CodeClientConfig, "client_id" | "scope" | "callback">)} */ export interface ImplicitFlowOptions extends Omit<CodeClientConfig, "client_id" | "scope" | "callback"> { /** * On success callback * * @memberof ImplicitFlowOptions */ onSuccess?: (response: ImplicitFlowSuccessResponse) => void; /** * On error callback * * @memberof ImplicitFlowOptions */ onError?: (errorResponse: ImplicitFlowErrorResponse) => void; /** * Authorization scopes * * @type {(MaybeRef<string> | MaybeRef<string[]>)} * @see https://developers.google.com/identity/protocols/oauth2/scopes * @memberof ImplicitFlowOptions */ scope?: MaybeRef<string> | MaybeRef<string[]>; } /** * Result of composable * * @export * @interface UseCodeClientReturn */ export interface UseCodeClientReturn { /** * Is script is ready to be used? * * @type {Readonly<Ref<boolean>>} * @memberof UseCodeClientReturn */ isReady: Readonly<Ref<boolean>>; /** * Execute login with code client * * @memberof UseCodeClientReturn */ login: () => void | undefined; /** * Get a URL to perform code request without actually redirecting user. * This is useful for platforms like _Electron/Tauri_ for redirecting user with system browser * * @type {Readonly<ComputedRef<string>>} * @memberof UseCodeClientReturn */ codeRequestRedirectUrl: Readonly<Ref<string | null>>; } /** * Initiate login with implicit flow using code client. Return values of the composable can be used * to trigger the login flow and determine the readiness of the client. * It also provides callbacks such as `onSuccess` and `onError` that can be used to obtain the results from the login client. * * @export * @param {ImplicitFlowOptions} [options={}] * @see https://developers.google.com/identity/oauth2/web/guides/use-code-model * @return {*} {UseCodeClientReturn} */ export default function useCodeClient(options?: ImplicitFlowOptions): UseCodeClientReturn;