Google Authentication Capacitor Plugin
npm install @kim5257/capacitor-google-authenticationGoogle Authentication Capacitor Plugin
``bash`
npm install @kim5257/capacitor-google-authentication
npx cap sync
* initialize(...)
* verifyPhoneNumber(...)
* confirmPhoneNumber(...)
* createUserWithEmailAndPassword(...)
* signInWithEmailAndPassword(...)
* signInWithGoogle()
* signInWithCustomToken(...)
* signInWithApple()
* getIdToken(...)
* getCurrentUser()
* updateProfile(...)
* updateEmail(...)
* signOut()
* linkWithPhone(...)
* confirmLinkPhoneNumber(...)
* updatePhoneNumber(...)
* confirmUpdatePhoneNumber(...)
* echo(...)
* addListener('google.auth.phone.verify.completed', ...)
* addListener('google.auth.phone.code.sent', ...)
* addListener('google.auth.phone.verify.failed', ...)
* addListener('google.auth.state.update', ...)
* Interfaces
* Type Aliases
`typescript`
initialize(config: GoogleAuthenticationOptions) => Promise<{ result: 'success' | 'error'; }>
| Param | Type |
| ------------ | ----------------------------------------------------------------------------------- |
| config | GoogleAuthenticationOptions |
Returns: Promise<{ result: 'error' | 'success'; }>
--------------------
`typescript`
verifyPhoneNumber(options: { phone: string; elem?: HTMLElement; }) => Promise<{ result: 'success' | 'error'; }>
| Param | Type |
| ------------- | ------------------------------------------- |
| options | { phone: string; elem?: any; } |
Returns: Promise<{ result: 'error' | 'success'; }>
--------------------
`typescript`
confirmPhoneNumber(options: { code: string; }) => Promise<{ result: 'success' | 'error'; }>
| Param | Type |
| ------------- | ------------------------------ |
| options | { code: string; } |
Returns: Promise<{ result: 'error' | 'success'; }>
--------------------
`typescript`
createUserWithEmailAndPassword(options: { email: string; password: string; }) => Promise<{ result: "success" | "error"; idToken: string; }>
| Param | Type |
| ------------- | ------------------------------------------------- |
| options | { email: string; password: string; } |
Returns: Promise<{ result: 'error' | 'success'; idToken: string; }>
--------------------
`typescript`
signInWithEmailAndPassword(options: { email: string; password: string; }) => Promise<{ result: "success" | "error"; idToken: string; }>
| Param | Type |
| ------------- | ------------------------------------------------- |
| options | { email: string; password: string; } |
Returns: Promise<{ result: 'error' | 'success'; idToken: string; }>
--------------------
`typescript`
signInWithGoogle() => Promise<{ result: "success" | "error"; idToken: string; }>
Returns: Promise<{ result: 'error' | 'success'; idToken: string; }>
--------------------
`typescript`
signInWithCustomToken({ customToken }: { customToken: string; }) => Promise<{ result: "success" | "error"; idToken: string; }>
| Param | Type |
| --------- | ------------------------------------- |
| __0 | { customToken: string; } |
Returns: Promise<{ result: 'error' | 'success'; idToken: string; }>
--------------------
`typescript`
signInWithApple() => Promise<{ result: "success" | "error"; idToken: string; }>
Returns: Promise<{ result: 'error' | 'success'; idToken: string; }>
--------------------
`typescript`
getIdToken(options: { forceRefresh: boolean; }) => Promise<{ result: 'success' | 'error'; idToken: string; }>
| Param | Type |
| ------------- | --------------------------------------- |
| options | { forceRefresh: boolean; } |
Returns: Promise<{ result: 'error' | 'success'; idToken: string; }>
--------------------
`typescript`
getCurrentUser() => Promise<{ result: 'success' | 'error'; user: User | null | undefined; }>
Returns: Promise<{ result: 'error' | 'success'; user: User | null; }>
--------------------
`typescript`
updateProfile(options: { displayName?: string; photoUri?: string; }) => Promise<{ result: 'success' | 'error'; }>
| Param | Type |
| ------------- | --------------------------------------------------------- |
| options | { displayName?: string; photoUri?: string; } |
Returns: Promise<{ result: 'error' | 'success'; }>
--------------------
`typescript`
updateEmail(options: { email: string; }) => Promise<{ result: 'success' | 'error'; }>
| Param | Type |
| ------------- | ------------------------------- |
| options | { email: string; } |
Returns: Promise<{ result: 'error' | 'success'; }>
--------------------
`typescript`
signOut() => Promise<{ result: 'success' | 'error'; }>
Returns: Promise<{ result: 'error' | 'success'; }>
--------------------
`typescript`
linkWithPhone({ phone, elem }: { phone: string; elem: HTMLElement; }) => Promise<{ result: "success" | "error"; }>
| Param | Type |
| --------- | ------------------------------------------ |
| __0 | { phone: string; elem: any; } |
Returns: Promise<{ result: 'error' | 'success'; }>
--------------------
`typescript`
confirmLinkPhoneNumber(options: { code: string; }) => Promise<{ result: 'success' | 'error'; }>
| Param | Type |
| ------------- | ------------------------------ |
| options | { code: string; } |
Returns: Promise<{ result: 'error' | 'success'; }>
--------------------
`typescript`
updatePhoneNumber({ phone, elem }: { phone: string; elem: HTMLElement; }) => Promise<{ result: "success" | "error"; }>
| Param | Type |
| --------- | ------------------------------------------ |
| __0 | { phone: string; elem: any; } |
Returns: Promise<{ result: 'error' | 'success'; }>
--------------------
`typescript`
confirmUpdatePhoneNumber(options: { code: string; }) => Promise<{ result: 'success' | 'error'; }>
| Param | Type |
| ------------- | ------------------------------ |
| options | { code: string; } |
Returns: Promise<{ result: 'error' | 'success'; }>
--------------------
`typescript`
echo(options: { value: string; }) => Promise<{ value: string; }>
| Param | Type |
| ------------- | ------------------------------- |
| options | { value: string; } |
Returns: Promise<{ value: string; }>
--------------------
`typescript`
addListener(eventName: 'google.auth.phone.verify.completed', listenerFunc: (resp: { idToken: string; }) => void) => Promise
| Param | Type |
| ------------------ | ---------------------------------------------------- |
| eventName | 'google.auth.phone.verify.completed' |
| listenerFunc | (resp: { idToken: string; }) => void |
Returns: Promise<PluginListenerHandle>
--------------------
`typescript`
addListener(eventName: 'google.auth.phone.code.sent', listenerFunc: (resp: { verificationId: string | null; resendingToken: string | null; }) => void) => Promise
| Param | Type |
| ------------------ | --------------------------------------------------------------------------------------------------- |
| eventName | 'google.auth.phone.code.sent' |
| listenerFunc | (resp: { verificationId: string \| null; resendingToken: string \| null; }) => void |
Returns: Promise<PluginListenerHandle>
--------------------
`typescript`
addListener(eventName: 'google.auth.phone.verify.failed', listenerFunc: (resp: { message: string; }) => void) => Promise
| Param | Type |
| ------------------ | ---------------------------------------------------- |
| eventName | 'google.auth.phone.verify.failed' |
| listenerFunc | (resp: { message: string; }) => void |
Returns: Promise<PluginListenerHandle>
--------------------
`typescript`
addListener(eventName: 'google.auth.state.update', listenerFunc: (resp: { idToken: string; }) => void) => Promise
| Param | Type |
| ------------------ | ---------------------------------------------------- |
| eventName | 'google.auth.state.update' |
| listenerFunc | (resp: { idToken: string; }) => void |
Returns: Promise<PluginListenerHandle>
--------------------
#### GoogleAuthenticationOptions
| Prop | Type |
| -------------------- | --------------------------------------------- |
| googleClientId | string |
| persistence | 'SESSION' \| 'LOCAL' \| 'MEMORY' |
#### User
A user account.
| Prop | Type | Description |
| ------------------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| emailVerified | boolean | Whether the email has been verified with {@link sendEmailVerification} and {@link applyActionCode}. |
| isAnonymous | boolean | Whether the user is authenticated using the {@link ProviderId}.ANONYMOUS provider. |
| metadata | UserMetadata | Additional metadata around user creation and sign-in times. |
| providerData | UserInfo[] | Additional per provider such as displayName and profile information. |
| refreshToken | string | Refresh token used to reauthenticate the user. Avoid using this directly and prefer {@link User.getIdToken} to refresh the ID token instead. |
| tenantId | string \| null | The user's tenant ID. |
| Method | Signature | Description |
| -------------------- | ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| delete | () => Promise<void> | Deletes and signs out the user. |
| getIdToken | (forceRefresh?: boolean \| undefined) => Promise<string> | Returns a JSON Web Token (JWT) used to identify the user to a Firebase service. |
| getIdTokenResult | (forceRefresh?: boolean \| undefined) => Promise<IdTokenResult> | Returns a deserialized JSON Web Token (JWT) used to identify the user to a Firebase service. |
| reload | () => Promise<void> | Refreshes the user, if signed in. |
| toJSON | () => object | Returns a JSON-serializable representation of this object. |
#### IdTokenResult
Interface representing ID token result obtained from {@link User.getIdTokenResult}.
| Prop | Type | Description |
| ------------------------ | --------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| authTime | string | The authentication time formatted as a UTC string. |
| expirationTime | string | The ID token expiration time formatted as a UTC string. |
| issuedAtTime | string | The ID token issuance time formatted as a UTC string. |
| signInProvider | string \| null | The sign-in provider through which the ID token was obtained (anonymous, custom, phone, password, etc). |
| signInSecondFactor | string \| null | The type of second factor associated with this session, provided the user was multi-factor authenticated (eg. phone, etc). |
| token | string | The Firebase Auth ID token JWT string. |
| claims | ParsedToken | The entire payload claims of the ID token including the standard reserved claims as well as the custom claims. |
#### ParsedToken
Interface representing a parsed ID token.
| Prop | Type | Description |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| 'exp' | string | Expiration time of the token. |
| 'sub' | string | UID of the user. |
| 'auth_time' | string | Time at which authentication was performed. |
| 'iat' | string | Issuance time of the token. |
| 'firebase' | { sign_in_provider?: string; sign_in_second_factor?: string; identities?: Record<string, string>; } | Firebase specific claims, containing the provider(s) used to authenticate the user. |
#### UserMetadata
Interface representing a user's metadata.
| Prop | Type | Description |
| -------------------- | ------------------- | ----------------------------- |
| creationTime | string | Time the user was created. |
| lastSignInTime | string | Time the user last signed in. |
#### UserInfo
User profile information, visible only to the Firebase project's apps.
| Prop | Type | Description |
| ----------------- | --------------------------- | ----------------------------------------------------------------------------------------- |
| displayName | string \| null | The display name of the user. |
| email | string \| null | The email of the user. |
| phoneNumber | string \| null | The phone number normalized based on the E.164 standard (e.g. +16505550101) for the user. |
| photoURL | string \| null | The profile photo URL of the user. |
| providerId | string | The provider used to authenticate the user. |
| uid | string | The user's unique ID, scoped to the project. |
#### PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove` | () => Promise<void> |
#### Record
Construct a type with a set of properties K of type T
{
[P in K]: T;
}