@clerk/expo-google-signin 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/android/build.gradle +39 -0
  3. package/android/src/main/AndroidManifest.xml +1 -0
  4. package/android/src/main/java/expo/modules/clerk/googlesignin/ClerkGoogleSignInModule.kt +257 -0
  5. package/app.plugin.d.ts +5 -0
  6. package/app.plugin.js +32 -0
  7. package/dist/google-one-tap/ClerkGoogleOneTapSignIn.d.ts +86 -0
  8. package/dist/google-one-tap/ClerkGoogleOneTapSignIn.d.ts.map +1 -0
  9. package/dist/google-one-tap/ClerkGoogleOneTapSignIn.js +165 -0
  10. package/dist/google-one-tap/ClerkGoogleOneTapSignIn.js.map +1 -0
  11. package/dist/google-one-tap/index.d.ts +3 -0
  12. package/dist/google-one-tap/index.d.ts.map +1 -0
  13. package/dist/google-one-tap/index.js +37 -0
  14. package/dist/google-one-tap/index.js.map +1 -0
  15. package/dist/google-one-tap/types.d.ts +161 -0
  16. package/dist/google-one-tap/types.d.ts.map +1 -0
  17. package/dist/google-one-tap/types.js +17 -0
  18. package/dist/google-one-tap/types.js.map +1 -0
  19. package/dist/index.d.ts +3 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +29 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/specs/NativeClerkGoogleSignIn.android.d.ts +11 -0
  24. package/dist/specs/NativeClerkGoogleSignIn.android.d.ts.map +1 -0
  25. package/dist/specs/NativeClerkGoogleSignIn.android.js +26 -0
  26. package/dist/specs/NativeClerkGoogleSignIn.android.js.map +1 -0
  27. package/dist/specs/NativeClerkGoogleSignIn.d.ts +11 -0
  28. package/dist/specs/NativeClerkGoogleSignIn.d.ts.map +1 -0
  29. package/dist/specs/NativeClerkGoogleSignIn.js +26 -0
  30. package/dist/specs/NativeClerkGoogleSignIn.js.map +1 -0
  31. package/dist/useSignInWithGoogle.android.d.ts +46 -0
  32. package/dist/useSignInWithGoogle.android.d.ts.map +1 -0
  33. package/dist/useSignInWithGoogle.android.js +30 -0
  34. package/dist/useSignInWithGoogle.android.js.map +1 -0
  35. package/dist/useSignInWithGoogle.d.ts +52 -0
  36. package/dist/useSignInWithGoogle.d.ts.map +1 -0
  37. package/dist/useSignInWithGoogle.ios.d.ts +46 -0
  38. package/dist/useSignInWithGoogle.ios.d.ts.map +1 -0
  39. package/dist/useSignInWithGoogle.ios.js +30 -0
  40. package/dist/useSignInWithGoogle.ios.js.map +1 -0
  41. package/dist/useSignInWithGoogle.js +40 -0
  42. package/dist/useSignInWithGoogle.js.map +1 -0
  43. package/dist/useSignInWithGoogle.shared.d.ts +29 -0
  44. package/dist/useSignInWithGoogle.shared.d.ts.map +1 -0
  45. package/dist/useSignInWithGoogle.shared.js +167 -0
  46. package/dist/useSignInWithGoogle.shared.js.map +1 -0
  47. package/dist/useSignInWithGoogle.types.d.ts +13 -0
  48. package/dist/useSignInWithGoogle.types.d.ts.map +1 -0
  49. package/dist/useSignInWithGoogle.types.js +17 -0
  50. package/dist/useSignInWithGoogle.types.js.map +1 -0
  51. package/expo-module.config.json +9 -0
  52. package/ios/ClerkGoogleSignIn.podspec +27 -0
  53. package/ios/ClerkGoogleSignInModule.swift +199 -0
  54. package/package.json +73 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Clerk Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,39 @@
1
+ apply plugin: 'com.android.library'
2
+ apply plugin: 'kotlin-android'
3
+ apply plugin: 'maven-publish'
4
+
5
+ group = 'expo.modules.clerk.googlesignin'
6
+ version = '1.0.0'
7
+
8
+ def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
9
+ apply from: expoModulesCorePlugin
10
+ applyKotlinExpoModulesCorePlugin()
11
+ useCoreDependencies()
12
+ useExpoPublishing()
13
+
14
+ buildscript {
15
+ ext.safeExtGet = { prop, fallback ->
16
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
17
+ }
18
+ }
19
+
20
+ android {
21
+ namespace "expo.modules.clerk.googlesignin"
22
+
23
+ compileSdkVersion safeExtGet("compileSdkVersion", 36)
24
+
25
+ defaultConfig {
26
+ minSdkVersion safeExtGet("minSdkVersion", 24)
27
+ targetSdkVersion safeExtGet("targetSdkVersion", 36)
28
+ versionCode 1
29
+ versionName "1.0.0"
30
+ }
31
+ }
32
+
33
+ dependencies {
34
+ implementation project(':expo-modules-core')
35
+ implementation "androidx.credentials:credentials:1.3.0"
36
+ implementation "androidx.credentials:credentials-play-services-auth:1.3.0"
37
+ implementation "com.google.android.libraries.identity.googleid:googleid:1.1.1"
38
+ implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"
39
+ }
@@ -0,0 +1 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" />
@@ -0,0 +1,257 @@
1
+ package expo.modules.clerk.googlesignin
2
+
3
+ import androidx.credentials.ClearCredentialStateRequest
4
+ import androidx.credentials.CredentialManager
5
+ import androidx.credentials.CustomCredential
6
+ import androidx.credentials.GetCredentialRequest
7
+ import androidx.credentials.GetCredentialResponse
8
+ import androidx.credentials.exceptions.GetCredentialCancellationException
9
+ import androidx.credentials.exceptions.GetCredentialException
10
+ import androidx.credentials.exceptions.NoCredentialException
11
+ import com.google.android.libraries.identity.googleid.GetGoogleIdOption
12
+ import com.google.android.libraries.identity.googleid.GetSignInWithGoogleOption
13
+ import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential
14
+ import com.google.android.libraries.identity.googleid.GoogleIdTokenParsingException
15
+ import expo.modules.kotlin.Promise
16
+ import expo.modules.kotlin.modules.Module
17
+ import expo.modules.kotlin.modules.ModuleDefinition
18
+ import kotlinx.coroutines.CoroutineScope
19
+ import kotlinx.coroutines.Dispatchers
20
+ import kotlinx.coroutines.launch
21
+
22
+ class ClerkGoogleSignInModule : Module() {
23
+ private var webClientId: String? = null
24
+ private var hostedDomain: String? = null
25
+ private var autoSelectEnabled: Boolean = false
26
+ private val mainScope = CoroutineScope(Dispatchers.Main)
27
+
28
+ private val credentialManager: CredentialManager
29
+ get() = CredentialManager.create(requireNotNull(appContext.reactContext))
30
+
31
+ override fun definition() = ModuleDefinition {
32
+ Name("ClerkGoogleSignIn")
33
+
34
+ Function("configure") { params: Map<String, Any?> ->
35
+ configure(params)
36
+ }
37
+
38
+ AsyncFunction("signIn") { params: Map<String, Any?>?, promise: Promise ->
39
+ signIn(params, promise)
40
+ }
41
+
42
+ AsyncFunction("createAccount") { params: Map<String, Any?>?, promise: Promise ->
43
+ createAccount(params, promise)
44
+ }
45
+
46
+ AsyncFunction("presentExplicitSignIn") { params: Map<String, Any?>?, promise: Promise ->
47
+ presentExplicitSignIn(params, promise)
48
+ }
49
+
50
+ AsyncFunction("signOut") { promise: Promise ->
51
+ signOut(promise)
52
+ }
53
+ }
54
+
55
+ // MARK: - configure
56
+
57
+ private fun configure(params: Map<String, Any?>) {
58
+ webClientId = params["webClientId"] as? String
59
+ hostedDomain = params["hostedDomain"] as? String
60
+ autoSelectEnabled = params["autoSelectEnabled"] as? Boolean ?: false
61
+ }
62
+
63
+ // MARK: - signIn
64
+
65
+ private fun signIn(params: Map<String, Any?>?, promise: Promise) {
66
+ val clientId = webClientId ?: run {
67
+ promise.reject("NOT_CONFIGURED", "Google Sign-In is not configured. Call configure() first.", null)
68
+ return
69
+ }
70
+
71
+ val activity = appContext.currentActivity ?: run {
72
+ promise.reject("E_ACTIVITY_UNAVAILABLE", "Activity is not available", null)
73
+ return
74
+ }
75
+
76
+ mainScope.launch {
77
+ try {
78
+ val filterByAuthorized = params?.get("filterByAuthorizedAccounts") as? Boolean ?: true
79
+ val nonce = params?.get("nonce") as? String
80
+
81
+ val googleIdOption = GetGoogleIdOption.Builder()
82
+ .setFilterByAuthorizedAccounts(filterByAuthorized)
83
+ .setServerClientId(clientId)
84
+ .setAutoSelectEnabled(autoSelectEnabled)
85
+ .apply {
86
+ nonce?.let { setNonce(it) }
87
+ }
88
+ .build()
89
+
90
+ val request = GetCredentialRequest.Builder()
91
+ .addCredentialOption(googleIdOption)
92
+ .build()
93
+
94
+ val result = credentialManager.getCredential(
95
+ request = request,
96
+ context = activity
97
+ )
98
+
99
+ handleSignInResult(result, promise)
100
+ } catch (e: GetCredentialCancellationException) {
101
+ promise.reject("SIGN_IN_CANCELLED", "User cancelled the sign-in flow", e)
102
+ } catch (e: NoCredentialException) {
103
+ promise.reject("NO_SAVED_CREDENTIAL_FOUND", "No saved credential found", e)
104
+ } catch (e: GetCredentialException) {
105
+ promise.reject("GOOGLE_SIGN_IN_ERROR", e.message ?: "Unknown error", e)
106
+ } catch (e: Exception) {
107
+ promise.reject("GOOGLE_SIGN_IN_ERROR", e.message ?: "Unknown error", e)
108
+ }
109
+ }
110
+ }
111
+
112
+ // MARK: - createAccount
113
+
114
+ private fun createAccount(params: Map<String, Any?>?, promise: Promise) {
115
+ val clientId = webClientId ?: run {
116
+ promise.reject("NOT_CONFIGURED", "Google Sign-In is not configured. Call configure() first.", null)
117
+ return
118
+ }
119
+
120
+ val activity = appContext.currentActivity ?: run {
121
+ promise.reject("E_ACTIVITY_UNAVAILABLE", "Activity is not available", null)
122
+ return
123
+ }
124
+
125
+ mainScope.launch {
126
+ try {
127
+ val nonce = params?.get("nonce") as? String
128
+
129
+ val googleIdOption = GetGoogleIdOption.Builder()
130
+ .setFilterByAuthorizedAccounts(false) // Show all accounts for creation
131
+ .setServerClientId(clientId)
132
+ .apply {
133
+ nonce?.let { setNonce(it) }
134
+ }
135
+ .build()
136
+
137
+ val request = GetCredentialRequest.Builder()
138
+ .addCredentialOption(googleIdOption)
139
+ .build()
140
+
141
+ val result = credentialManager.getCredential(
142
+ request = request,
143
+ context = activity
144
+ )
145
+
146
+ handleSignInResult(result, promise)
147
+ } catch (e: GetCredentialCancellationException) {
148
+ promise.reject("SIGN_IN_CANCELLED", "User cancelled the sign-in flow", e)
149
+ } catch (e: NoCredentialException) {
150
+ promise.reject("NO_SAVED_CREDENTIAL_FOUND", "No saved credential found", e)
151
+ } catch (e: GetCredentialException) {
152
+ promise.reject("GOOGLE_SIGN_IN_ERROR", e.message ?: "Unknown error", e)
153
+ } catch (e: Exception) {
154
+ promise.reject("GOOGLE_SIGN_IN_ERROR", e.message ?: "Unknown error", e)
155
+ }
156
+ }
157
+ }
158
+
159
+ // MARK: - presentExplicitSignIn
160
+
161
+ private fun presentExplicitSignIn(params: Map<String, Any?>?, promise: Promise) {
162
+ val clientId = webClientId ?: run {
163
+ promise.reject("NOT_CONFIGURED", "Google Sign-In is not configured. Call configure() first.", null)
164
+ return
165
+ }
166
+
167
+ val activity = appContext.currentActivity ?: run {
168
+ promise.reject("E_ACTIVITY_UNAVAILABLE", "Activity is not available", null)
169
+ return
170
+ }
171
+
172
+ mainScope.launch {
173
+ try {
174
+ val nonce = params?.get("nonce") as? String
175
+
176
+ val signInWithGoogleOption = GetSignInWithGoogleOption.Builder(clientId)
177
+ .apply {
178
+ nonce?.let { setNonce(it) }
179
+ hostedDomain?.let { setHostedDomainFilter(it) }
180
+ }
181
+ .build()
182
+
183
+ val request = GetCredentialRequest.Builder()
184
+ .addCredentialOption(signInWithGoogleOption)
185
+ .build()
186
+
187
+ val result = credentialManager.getCredential(
188
+ request = request,
189
+ context = activity
190
+ )
191
+
192
+ handleSignInResult(result, promise)
193
+ } catch (e: GetCredentialCancellationException) {
194
+ promise.reject("SIGN_IN_CANCELLED", "User cancelled the sign-in flow", e)
195
+ } catch (e: GetCredentialException) {
196
+ promise.reject("GOOGLE_SIGN_IN_ERROR", e.message ?: "Unknown error", e)
197
+ } catch (e: Exception) {
198
+ promise.reject("GOOGLE_SIGN_IN_ERROR", e.message ?: "Unknown error", e)
199
+ }
200
+ }
201
+ }
202
+
203
+ // MARK: - signOut
204
+
205
+ private fun signOut(promise: Promise) {
206
+ mainScope.launch {
207
+ try {
208
+ credentialManager.clearCredentialState(ClearCredentialStateRequest())
209
+ promise.resolve(null)
210
+ } catch (e: Exception) {
211
+ promise.reject("GOOGLE_SIGN_IN_ERROR", e.message ?: "Failed to sign out", e)
212
+ }
213
+ }
214
+ }
215
+
216
+ // MARK: - Helpers
217
+
218
+ private fun handleSignInResult(result: GetCredentialResponse, promise: Promise) {
219
+ when (val credential = result.credential) {
220
+ is CustomCredential -> {
221
+ if (credential.type == GoogleIdTokenCredential.TYPE_GOOGLE_ID_TOKEN_CREDENTIAL) {
222
+ try {
223
+ val googleIdTokenCredential = GoogleIdTokenCredential.createFrom(credential.data)
224
+
225
+ val user = mapOf(
226
+ "id" to googleIdTokenCredential.id,
227
+ "email" to googleIdTokenCredential.id,
228
+ "name" to googleIdTokenCredential.displayName,
229
+ "givenName" to googleIdTokenCredential.givenName,
230
+ "familyName" to googleIdTokenCredential.familyName,
231
+ "photo" to googleIdTokenCredential.profilePictureUri?.toString()
232
+ )
233
+
234
+ val data = mapOf(
235
+ "idToken" to googleIdTokenCredential.idToken,
236
+ "user" to user
237
+ )
238
+
239
+ promise.resolve(
240
+ mapOf(
241
+ "type" to "success",
242
+ "data" to data
243
+ )
244
+ )
245
+ } catch (e: GoogleIdTokenParsingException) {
246
+ promise.reject("GOOGLE_SIGN_IN_ERROR", "Failed to parse Google ID token: ${e.message}", e)
247
+ }
248
+ } else {
249
+ promise.reject("GOOGLE_SIGN_IN_ERROR", "Unexpected credential type: ${credential.type}", null)
250
+ }
251
+ }
252
+ else -> {
253
+ promise.reject("GOOGLE_SIGN_IN_ERROR", "Unexpected credential type", null)
254
+ }
255
+ }
256
+ }
257
+ }
@@ -0,0 +1,5 @@
1
+ import type { ConfigPlugin } from '@expo/config-plugins';
2
+
3
+ declare const withClerkExpoGoogleSignIn: ConfigPlugin;
4
+
5
+ export = withClerkExpoGoogleSignIn;
package/app.plugin.js ADDED
@@ -0,0 +1,32 @@
1
+ const { withInfoPlist, createRunOncePlugin } = require('@expo/config-plugins');
2
+ const pkg = require('./package.json');
3
+
4
+ const withClerkExpoGoogleSignIn = config => {
5
+ const iosUrlScheme =
6
+ process.env.EXPO_PUBLIC_CLERK_GOOGLE_IOS_URL_SCHEME ||
7
+ (config.extra && config.extra.EXPO_PUBLIC_CLERK_GOOGLE_IOS_URL_SCHEME);
8
+
9
+ if (!iosUrlScheme) {
10
+ return config;
11
+ }
12
+
13
+ return withInfoPlist(config, modConfig => {
14
+ if (!Array.isArray(modConfig.modResults.CFBundleURLTypes)) {
15
+ modConfig.modResults.CFBundleURLTypes = [];
16
+ }
17
+
18
+ const schemeExists = modConfig.modResults.CFBundleURLTypes.some(urlType =>
19
+ urlType.CFBundleURLSchemes?.includes(iosUrlScheme),
20
+ );
21
+
22
+ if (!schemeExists) {
23
+ modConfig.modResults.CFBundleURLTypes.push({
24
+ CFBundleURLSchemes: [iosUrlScheme],
25
+ });
26
+ }
27
+
28
+ return modConfig;
29
+ });
30
+ };
31
+
32
+ module.exports = createRunOncePlugin(withClerkExpoGoogleSignIn, pkg.name, pkg.version);
@@ -0,0 +1,86 @@
1
+ import type { CancelledResponse, ConfigureParams, CreateAccountParams, ExplicitSignInParams, NoSavedCredentialFound, OneTapResponse, OneTapSuccessResponse, SignInParams } from './types';
2
+ /**
3
+ * Check if a response indicates the user cancelled the sign-in flow.
4
+ */
5
+ export declare function isCancelledResponse(response: OneTapResponse): response is CancelledResponse;
6
+ /**
7
+ * Check if a response indicates no saved credential was found.
8
+ */
9
+ export declare function isNoSavedCredentialFoundResponse(response: OneTapResponse): response is NoSavedCredentialFound;
10
+ /**
11
+ * Check if a response is a successful sign-in.
12
+ */
13
+ export declare function isSuccessResponse(response: OneTapResponse): response is OneTapSuccessResponse;
14
+ /**
15
+ * Check if an error has code and message properties (Google Sign-In error).
16
+ */
17
+ export declare function isErrorWithCode(error: unknown): error is {
18
+ code: string;
19
+ message: string;
20
+ };
21
+ /**
22
+ * Internal Google One Tap Sign-In module.
23
+ *
24
+ * This module provides native Google Sign-In functionality using Google's
25
+ * Credential Manager API with full nonce support for replay attack protection.
26
+ *
27
+ * @internal This is an internal module. Use the `useSignInWithGoogle` hook instead.
28
+ * @platform Android, iOS
29
+ */
30
+ export declare const ClerkGoogleOneTapSignIn: {
31
+ /**
32
+ * Configure Google Sign-In. Must be called before any sign-in methods.
33
+ *
34
+ * @param params - Configuration parameters
35
+ * @param params.webClientId - The web client ID from Google Cloud Console (required)
36
+ * @param params.hostedDomain - Optional domain restriction
37
+ * @param params.autoSelectEnabled - Auto-select for single credential (default: false)
38
+ */
39
+ configure(params: ConfigureParams): void;
40
+ /**
41
+ * Attempt to sign in with saved credentials (One Tap).
42
+ *
43
+ * This method will show the One Tap UI if there are saved credentials,
44
+ * or return a "noSavedCredentialFound" response if there are none.
45
+ *
46
+ * @param params - Sign-in parameters
47
+ * @param params.nonce - Cryptographic nonce for replay protection
48
+ * @param params.filterByAuthorizedAccounts - Android only. Filter to previously authorized accounts.
49
+ * @param params.hint - iOS only. Hint for Google Sign-In.
50
+ *
51
+ * @returns Promise resolving to OneTapResponse
52
+ */
53
+ signIn(params?: SignInParams): Promise<OneTapResponse>;
54
+ /**
55
+ * Create a new account (shows all Google accounts).
56
+ *
57
+ * This method shows the account picker with all available Google accounts,
58
+ * not just previously authorized ones.
59
+ *
60
+ * @param params - Create account parameters
61
+ * @param params.nonce - Cryptographic nonce for replay protection
62
+ *
63
+ * @returns Promise resolving to OneTapResponse
64
+ */
65
+ createAccount(params?: CreateAccountParams): Promise<OneTapResponse>;
66
+ /**
67
+ * Present explicit sign-in UI (Google Sign-In button flow).
68
+ *
69
+ * This shows the full Google Sign-In UI, similar to clicking a
70
+ * "Sign in with Google" button.
71
+ *
72
+ * @param params - Explicit sign-in parameters
73
+ * @param params.nonce - Cryptographic nonce for replay protection
74
+ *
75
+ * @returns Promise resolving to OneTapResponse
76
+ */
77
+ presentExplicitSignIn(params?: ExplicitSignInParams): Promise<OneTapResponse>;
78
+ /**
79
+ * Sign out and clear credential state.
80
+ *
81
+ * This disables automatic sign-in until the user signs in again.
82
+ */
83
+ signOut(): Promise<void>;
84
+ };
85
+ export type { ConfigureParams, SignInParams, CreateAccountParams, ExplicitSignInParams, OneTapResponse, OneTapSuccessResponse, CancelledResponse, NoSavedCredentialFound, GoogleUser, } from './types';
86
+ //# sourceMappingURL=ClerkGoogleOneTapSignIn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClerkGoogleOneTapSignIn.d.ts","sourceRoot":"","sources":["../../src/google-one-tap/ClerkGoogleOneTapSignIn.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,YAAY,EACb,MAAM,SAAS,CAAC;AAYjB;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,cAAc,GAAG,QAAQ,IAAI,iBAAiB,CAE3F;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,cAAc,GAAG,QAAQ,IAAI,sBAAsB,CAE7G;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,cAAc,GAAG,QAAQ,IAAI,qBAAqB,CAE7F;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAS1F;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB;IAClC;;;;;;;OAOG;sBACe,eAAe,GAAG,IAAI;IAIxC;;;;;;;;;;;;OAYG;oBACmB,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;IAgB5D;;;;;;;;;;OAUG;2BAC0B,mBAAmB,GAAG,OAAO,CAAC,cAAc,CAAC;IAgB1E;;;;;;;;;;OAUG;mCACkC,oBAAoB,GAAG,OAAO,CAAC,cAAc,CAAC;IAanF;;;;OAIG;eACc,OAAO,CAAC,IAAI,CAAC;CAG/B,CAAC;AAEF,YAAY,EACV,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACd,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACtB,UAAU,GACX,MAAM,SAAS,CAAC"}
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var ClerkGoogleOneTapSignIn_exports = {};
30
+ __export(ClerkGoogleOneTapSignIn_exports, {
31
+ ClerkGoogleOneTapSignIn: () => ClerkGoogleOneTapSignIn,
32
+ isCancelledResponse: () => isCancelledResponse,
33
+ isErrorWithCode: () => isErrorWithCode,
34
+ isNoSavedCredentialFoundResponse: () => isNoSavedCredentialFoundResponse,
35
+ isSuccessResponse: () => isSuccessResponse
36
+ });
37
+ module.exports = __toCommonJS(ClerkGoogleOneTapSignIn_exports);
38
+ var import_NativeClerkGoogleSignIn = __toESM(require("../specs/NativeClerkGoogleSignIn"));
39
+ function getNativeModule() {
40
+ if (!import_NativeClerkGoogleSignIn.default) {
41
+ throw new Error(
42
+ "ClerkGoogleSignIn native module is not available. Ensure the @clerk/expo-google-signin plugin is added to your app.json and you have run a development build."
43
+ );
44
+ }
45
+ return import_NativeClerkGoogleSignIn.default;
46
+ }
47
+ function isCancelledResponse(response) {
48
+ return response.type === "cancelled";
49
+ }
50
+ function isNoSavedCredentialFoundResponse(response) {
51
+ return response.type === "noSavedCredentialFound";
52
+ }
53
+ function isSuccessResponse(response) {
54
+ return response.type === "success";
55
+ }
56
+ function isErrorWithCode(error) {
57
+ return error !== null && typeof error === "object" && "code" in error && typeof error.code === "string" && "message" in error && typeof error.message === "string";
58
+ }
59
+ const ClerkGoogleOneTapSignIn = {
60
+ /**
61
+ * Configure Google Sign-In. Must be called before any sign-in methods.
62
+ *
63
+ * @param params - Configuration parameters
64
+ * @param params.webClientId - The web client ID from Google Cloud Console (required)
65
+ * @param params.hostedDomain - Optional domain restriction
66
+ * @param params.autoSelectEnabled - Auto-select for single credential (default: false)
67
+ */
68
+ configure(params) {
69
+ getNativeModule().configure(params);
70
+ },
71
+ /**
72
+ * Attempt to sign in with saved credentials (One Tap).
73
+ *
74
+ * This method will show the One Tap UI if there are saved credentials,
75
+ * or return a "noSavedCredentialFound" response if there are none.
76
+ *
77
+ * @param params - Sign-in parameters
78
+ * @param params.nonce - Cryptographic nonce for replay protection
79
+ * @param params.filterByAuthorizedAccounts - Android only. Filter to previously authorized accounts.
80
+ * @param params.hint - iOS only. Hint for Google Sign-In.
81
+ *
82
+ * @returns Promise resolving to OneTapResponse
83
+ */
84
+ async signIn(params) {
85
+ try {
86
+ return await getNativeModule().signIn(params != null ? params : null);
87
+ } catch (error) {
88
+ if (isErrorWithCode(error)) {
89
+ if (error.code === "SIGN_IN_CANCELLED") {
90
+ return { type: "cancelled", data: null };
91
+ }
92
+ if (error.code === "NO_SAVED_CREDENTIAL_FOUND") {
93
+ return { type: "noSavedCredentialFound", data: null };
94
+ }
95
+ }
96
+ throw error;
97
+ }
98
+ },
99
+ /**
100
+ * Create a new account (shows all Google accounts).
101
+ *
102
+ * This method shows the account picker with all available Google accounts,
103
+ * not just previously authorized ones.
104
+ *
105
+ * @param params - Create account parameters
106
+ * @param params.nonce - Cryptographic nonce for replay protection
107
+ *
108
+ * @returns Promise resolving to OneTapResponse
109
+ */
110
+ async createAccount(params) {
111
+ try {
112
+ return await getNativeModule().createAccount(params != null ? params : null);
113
+ } catch (error) {
114
+ if (isErrorWithCode(error)) {
115
+ if (error.code === "SIGN_IN_CANCELLED") {
116
+ return { type: "cancelled", data: null };
117
+ }
118
+ if (error.code === "NO_SAVED_CREDENTIAL_FOUND") {
119
+ return { type: "noSavedCredentialFound", data: null };
120
+ }
121
+ }
122
+ throw error;
123
+ }
124
+ },
125
+ /**
126
+ * Present explicit sign-in UI (Google Sign-In button flow).
127
+ *
128
+ * This shows the full Google Sign-In UI, similar to clicking a
129
+ * "Sign in with Google" button.
130
+ *
131
+ * @param params - Explicit sign-in parameters
132
+ * @param params.nonce - Cryptographic nonce for replay protection
133
+ *
134
+ * @returns Promise resolving to OneTapResponse
135
+ */
136
+ async presentExplicitSignIn(params) {
137
+ try {
138
+ return await getNativeModule().presentExplicitSignIn(params != null ? params : null);
139
+ } catch (error) {
140
+ if (isErrorWithCode(error)) {
141
+ if (error.code === "SIGN_IN_CANCELLED") {
142
+ return { type: "cancelled", data: null };
143
+ }
144
+ }
145
+ throw error;
146
+ }
147
+ },
148
+ /**
149
+ * Sign out and clear credential state.
150
+ *
151
+ * This disables automatic sign-in until the user signs in again.
152
+ */
153
+ async signOut() {
154
+ await getNativeModule().signOut();
155
+ }
156
+ };
157
+ // Annotate the CommonJS export names for ESM import in node:
158
+ 0 && (module.exports = {
159
+ ClerkGoogleOneTapSignIn,
160
+ isCancelledResponse,
161
+ isErrorWithCode,
162
+ isNoSavedCredentialFoundResponse,
163
+ isSuccessResponse
164
+ });
165
+ //# sourceMappingURL=ClerkGoogleOneTapSignIn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/google-one-tap/ClerkGoogleOneTapSignIn.ts"],"sourcesContent":["import NativeClerkGoogleSignIn from '../specs/NativeClerkGoogleSignIn';\nimport type {\n CancelledResponse,\n ConfigureParams,\n CreateAccountParams,\n ExplicitSignInParams,\n NoSavedCredentialFound,\n OneTapResponse,\n OneTapSuccessResponse,\n SignInParams,\n} from './types';\n\nfunction getNativeModule(): NonNullable<typeof NativeClerkGoogleSignIn> {\n if (!NativeClerkGoogleSignIn) {\n throw new Error(\n 'ClerkGoogleSignIn native module is not available. ' +\n 'Ensure the @clerk/expo-google-signin plugin is added to your app.json and you have run a development build.',\n );\n }\n return NativeClerkGoogleSignIn;\n}\n\n/**\n * Check if a response indicates the user cancelled the sign-in flow.\n */\nexport function isCancelledResponse(response: OneTapResponse): response is CancelledResponse {\n return response.type === 'cancelled';\n}\n\n/**\n * Check if a response indicates no saved credential was found.\n */\nexport function isNoSavedCredentialFoundResponse(response: OneTapResponse): response is NoSavedCredentialFound {\n return response.type === 'noSavedCredentialFound';\n}\n\n/**\n * Check if a response is a successful sign-in.\n */\nexport function isSuccessResponse(response: OneTapResponse): response is OneTapSuccessResponse {\n return response.type === 'success';\n}\n\n/**\n * Check if an error has code and message properties (Google Sign-In error).\n */\nexport function isErrorWithCode(error: unknown): error is { code: string; message: string } {\n return (\n error !== null &&\n typeof error === 'object' &&\n 'code' in error &&\n typeof (error as { code: unknown }).code === 'string' &&\n 'message' in error &&\n typeof (error as { message: unknown }).message === 'string'\n );\n}\n\n/**\n * Internal Google One Tap Sign-In module.\n *\n * This module provides native Google Sign-In functionality using Google's\n * Credential Manager API with full nonce support for replay attack protection.\n *\n * @internal This is an internal module. Use the `useSignInWithGoogle` hook instead.\n * @platform Android, iOS\n */\nexport const ClerkGoogleOneTapSignIn = {\n /**\n * Configure Google Sign-In. Must be called before any sign-in methods.\n *\n * @param params - Configuration parameters\n * @param params.webClientId - The web client ID from Google Cloud Console (required)\n * @param params.hostedDomain - Optional domain restriction\n * @param params.autoSelectEnabled - Auto-select for single credential (default: false)\n */\n configure(params: ConfigureParams): void {\n getNativeModule().configure(params as any);\n },\n\n /**\n * Attempt to sign in with saved credentials (One Tap).\n *\n * This method will show the One Tap UI if there are saved credentials,\n * or return a \"noSavedCredentialFound\" response if there are none.\n *\n * @param params - Sign-in parameters\n * @param params.nonce - Cryptographic nonce for replay protection\n * @param params.filterByAuthorizedAccounts - Android only. Filter to previously authorized accounts.\n * @param params.hint - iOS only. Hint for Google Sign-In.\n *\n * @returns Promise resolving to OneTapResponse\n */\n async signIn(params?: SignInParams): Promise<OneTapResponse> {\n try {\n return (await getNativeModule().signIn((params as any) ?? null)) as unknown as OneTapResponse;\n } catch (error) {\n if (isErrorWithCode(error)) {\n if (error.code === 'SIGN_IN_CANCELLED') {\n return { type: 'cancelled', data: null };\n }\n if (error.code === 'NO_SAVED_CREDENTIAL_FOUND') {\n return { type: 'noSavedCredentialFound', data: null };\n }\n }\n throw error;\n }\n },\n\n /**\n * Create a new account (shows all Google accounts).\n *\n * This method shows the account picker with all available Google accounts,\n * not just previously authorized ones.\n *\n * @param params - Create account parameters\n * @param params.nonce - Cryptographic nonce for replay protection\n *\n * @returns Promise resolving to OneTapResponse\n */\n async createAccount(params?: CreateAccountParams): Promise<OneTapResponse> {\n try {\n return (await getNativeModule().createAccount((params as any) ?? null)) as unknown as OneTapResponse;\n } catch (error) {\n if (isErrorWithCode(error)) {\n if (error.code === 'SIGN_IN_CANCELLED') {\n return { type: 'cancelled', data: null };\n }\n if (error.code === 'NO_SAVED_CREDENTIAL_FOUND') {\n return { type: 'noSavedCredentialFound', data: null };\n }\n }\n throw error;\n }\n },\n\n /**\n * Present explicit sign-in UI (Google Sign-In button flow).\n *\n * This shows the full Google Sign-In UI, similar to clicking a\n * \"Sign in with Google\" button.\n *\n * @param params - Explicit sign-in parameters\n * @param params.nonce - Cryptographic nonce for replay protection\n *\n * @returns Promise resolving to OneTapResponse\n */\n async presentExplicitSignIn(params?: ExplicitSignInParams): Promise<OneTapResponse> {\n try {\n return (await getNativeModule().presentExplicitSignIn((params as any) ?? null)) as unknown as OneTapResponse;\n } catch (error) {\n if (isErrorWithCode(error)) {\n if (error.code === 'SIGN_IN_CANCELLED') {\n return { type: 'cancelled', data: null };\n }\n }\n throw error;\n }\n },\n\n /**\n * Sign out and clear credential state.\n *\n * This disables automatic sign-in until the user signs in again.\n */\n async signOut(): Promise<void> {\n await getNativeModule().signOut();\n },\n};\n\nexport type {\n ConfigureParams,\n SignInParams,\n CreateAccountParams,\n ExplicitSignInParams,\n OneTapResponse,\n OneTapSuccessResponse,\n CancelledResponse,\n NoSavedCredentialFound,\n GoogleUser,\n} from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qCAAoC;AAYpC,SAAS,kBAA+D;AACtE,MAAI,CAAC,+BAAAA,SAAyB;AAC5B,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AACA,SAAO,+BAAAA;AACT;AAKO,SAAS,oBAAoB,UAAyD;AAC3F,SAAO,SAAS,SAAS;AAC3B;AAKO,SAAS,iCAAiC,UAA8D;AAC7G,SAAO,SAAS,SAAS;AAC3B;AAKO,SAAS,kBAAkB,UAA6D;AAC7F,SAAO,SAAS,SAAS;AAC3B;AAKO,SAAS,gBAAgB,OAA4D;AAC1F,SACE,UAAU,QACV,OAAO,UAAU,YACjB,UAAU,SACV,OAAQ,MAA4B,SAAS,YAC7C,aAAa,SACb,OAAQ,MAA+B,YAAY;AAEvD;AAWO,MAAM,0BAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASrC,UAAU,QAA+B;AACvC,oBAAgB,EAAE,UAAU,MAAa;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,MAAM,OAAO,QAAgD;AAC3D,QAAI;AACF,aAAQ,MAAM,gBAAgB,EAAE,OAAQ,0BAAkB,IAAI;AAAA,IAChE,SAAS,OAAO;AACd,UAAI,gBAAgB,KAAK,GAAG;AAC1B,YAAI,MAAM,SAAS,qBAAqB;AACtC,iBAAO,EAAE,MAAM,aAAa,MAAM,KAAK;AAAA,QACzC;AACA,YAAI,MAAM,SAAS,6BAA6B;AAC9C,iBAAO,EAAE,MAAM,0BAA0B,MAAM,KAAK;AAAA,QACtD;AAAA,MACF;AACA,YAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,MAAM,cAAc,QAAuD;AACzE,QAAI;AACF,aAAQ,MAAM,gBAAgB,EAAE,cAAe,0BAAkB,IAAI;AAAA,IACvE,SAAS,OAAO;AACd,UAAI,gBAAgB,KAAK,GAAG;AAC1B,YAAI,MAAM,SAAS,qBAAqB;AACtC,iBAAO,EAAE,MAAM,aAAa,MAAM,KAAK;AAAA,QACzC;AACA,YAAI,MAAM,SAAS,6BAA6B;AAC9C,iBAAO,EAAE,MAAM,0BAA0B,MAAM,KAAK;AAAA,QACtD;AAAA,MACF;AACA,YAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,MAAM,sBAAsB,QAAwD;AAClF,QAAI;AACF,aAAQ,MAAM,gBAAgB,EAAE,sBAAuB,0BAAkB,IAAI;AAAA,IAC/E,SAAS,OAAO;AACd,UAAI,gBAAgB,KAAK,GAAG;AAC1B,YAAI,MAAM,SAAS,qBAAqB;AACtC,iBAAO,EAAE,MAAM,aAAa,MAAM,KAAK;AAAA,QACzC;AAAA,MACF;AACA,YAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,UAAyB;AAC7B,UAAM,gBAAgB,EAAE,QAAQ;AAAA,EAClC;AACF;","names":["NativeClerkGoogleSignIn"]}
@@ -0,0 +1,3 @@
1
+ export { ClerkGoogleOneTapSignIn, isCancelledResponse, isNoSavedCredentialFoundResponse, isSuccessResponse, isErrorWithCode, } from './ClerkGoogleOneTapSignIn';
2
+ export type { ConfigureParams, SignInParams, CreateAccountParams, ExplicitSignInParams, OneTapResponse, OneTapSuccessResponse, CancelledResponse, NoSavedCredentialFound, GoogleUser, GoogleSignInError, GoogleSignInErrorCode, } from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/google-one-tap/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,gCAAgC,EAChC,iBAAiB,EACjB,eAAe,GAChB,MAAM,2BAA2B,CAAC;AAEnC,YAAY,EACV,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACd,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACtB,UAAU,EACV,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,SAAS,CAAC"}