d13100ebf3
Update draft releases / main (push) Has been cancelled
Build and push docs image / build-image (push) Has been cancelled
Build Web Application / build-web (macos-latest) (push) Has been cancelled
Build Web Application / build-web (ubuntu-latest) (push) Has been cancelled
Python Code Quality Checks / build (push) Has been cancelled
Test Python / test-python (macos-latest, 3.10) (push) Has been cancelled
Test Python / test-python (macos-latest, 3.11) (push) Has been cancelled
Test Python / test-python (ubuntu-latest, 3.10) (push) Has been cancelled
Test Python / test-python (ubuntu-latest, 3.11) (push) Has been cancelled
28 lines
896 B
TypeScript
28 lines
896 B
TypeScript
import { CredentialResponse, IdConfiguration } from 'google-one-tap';
|
|
|
|
export default function googleOneTap(
|
|
{ client_id, auto_select = false, cancel_on_tap_outside = false, context = 'signin' }: IdConfiguration,
|
|
callback: (response: CredentialResponse) => void,
|
|
otherOptions?: Omit<IdConfiguration, 'client_id'>,
|
|
) {
|
|
const contextValue = ['signin', 'signup', 'use'].includes(context) ? context : 'signin';
|
|
if (!client_id) {
|
|
throw new Error('client_id is required');
|
|
}
|
|
if (typeof window !== 'undefined' && window.document) {
|
|
try {
|
|
window.google.accounts.id.initialize({
|
|
client_id: client_id,
|
|
callback: callback,
|
|
auto_select: auto_select,
|
|
cancel_on_tap_outside: cancel_on_tap_outside,
|
|
context: contextValue,
|
|
...otherOptions,
|
|
});
|
|
window.google.accounts.id.prompt();
|
|
} catch {
|
|
/* empty */
|
|
}
|
|
}
|
|
}
|