Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tall-cameras-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/expo": patch
---

Revert the iOS Google Sign-In module registration to restore the previous iOS build behavior.
3 changes: 0 additions & 3 deletions packages/expo/expo-module.config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"platforms": ["apple", "android"],
"apple": {
"modules": ["ClerkGoogleSignInModule"]
},
"android": {
"modules": [
"expo.modules.clerk.ClerkExpoModule",
Expand Down
4 changes: 1 addition & 3 deletions packages/expo/ios/ClerkGoogleSignIn.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ Pod::Spec.new do |s|
s.static_framework = true

s.dependency 'GoogleSignIn', '~> 9.0'
s.dependency 'GoogleUtilities'
s.dependency 'RecaptchaInterop'

# Only include the Google Sign-In module files
s.source_files = 'ClerkGoogleSignInModule.swift'
s.source_files = 'ClerkGoogleSignInModule.swift', 'ClerkGoogleSignInModule.m'

install_modules_dependencies(s)
end
22 changes: 22 additions & 0 deletions packages/expo/ios/ClerkGoogleSignInModule.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_MODULE(ClerkGoogleSignIn, NSObject)

RCT_EXTERN_METHOD(configure:(NSDictionary *)params)

RCT_EXTERN_METHOD(signIn:(NSDictionary *)params
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(createAccount:(NSDictionary *)params
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(presentExplicitSignIn:(NSDictionary *)params
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(signOut:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)

@end
164 changes: 81 additions & 83 deletions packages/expo/ios/ClerkGoogleSignInModule.swift
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
import ExpoModulesCore
import React
import GoogleSignIn

public class ClerkGoogleSignInModule: Module {
private var clientId: String?
private var hostedDomain: String?

public func definition() -> ModuleDefinition {
Name("ClerkGoogleSignIn")

Function("configure") { (params: [String: Any?]) in
self.configure(params)
}

AsyncFunction("signIn") { (params: [String: Any?]?, promise: Promise) in
self.signIn(params, promise: promise)
}.runOnQueue(.main)

AsyncFunction("createAccount") { (params: [String: Any?]?, promise: Promise) in
self.createAccount(params, promise: promise)
}.runOnQueue(.main)
@objc(ClerkGoogleSignIn)
class ClerkGoogleSignInModule: NSObject, RCTBridgeModule {

AsyncFunction("presentExplicitSignIn") { (params: [String: Any?]?, promise: Promise) in
self.presentExplicitSignIn(params, promise: promise)
}.runOnQueue(.main)
static func moduleName() -> String! {
return "ClerkGoogleSignIn"
}

AsyncFunction("signOut") { (promise: Promise) in
self.signOut(promise: promise)
}.runOnQueue(.main)
@objc static func requiresMainQueueSetup() -> Bool {
return false
}

private var clientId: String?
private var hostedDomain: String?

// MARK: - configure

private func configure(_ params: [String: Any?]) {
@objc func configure(_ params: NSDictionary) {
let webClientId = self.nonEmptyClientId(params["webClientId"] as? String)
let iosClientId = self.nonEmptyClientId(params["iosClientId"] as? String)
self.clientId = iosClientId ?? webClientId
Expand All @@ -48,91 +34,101 @@ public class ClerkGoogleSignInModule: Module {

// MARK: - signIn

private func signIn(_ params: [String: Any?]?, promise: Promise) {
@objc func signIn(_ params: NSDictionary?,
resolve: @escaping RCTPromiseResolveBlock,
reject: @escaping RCTPromiseRejectBlock) {
guard self.clientId != nil else {
promise.reject("NOT_CONFIGURED", "Google Sign-In is not configured. Call configure() first.")
reject("NOT_CONFIGURED", "Google Sign-In is not configured. Call configure() first.", nil)
return
}

guard let presentingVC = self.getPresentingViewController() else {
promise.reject("GOOGLE_SIGN_IN_ERROR", "No presenting view controller available")
return
}
DispatchQueue.main.async {
guard let presentingVC = self.getPresentingViewController() else {
reject("GOOGLE_SIGN_IN_ERROR", "No presenting view controller available", nil)
return
}

let filterByAuthorized = params?["filterByAuthorizedAccounts"] as? Bool ?? false
let hint: String? = filterByAuthorized
? GIDSignIn.sharedInstance.currentUser?.profile?.email
: nil
let nonce = params?["nonce"] as? String

GIDSignIn.sharedInstance.signIn(
withPresenting: presentingVC,
hint: hint,
additionalScopes: nil,
nonce: nonce,
completion: { result, error in
self.handleSignInResult(result: result, error: error, promise: promise)
let filterByAuthorized = params?["filterByAuthorizedAccounts"] as? Bool ?? false
let hint: String? = filterByAuthorized
? GIDSignIn.sharedInstance.currentUser?.profile?.email
: nil
let nonce = params?["nonce"] as? String

GIDSignIn.sharedInstance.signIn(
withPresenting: presentingVC,
hint: hint,
additionalScopes: nil,
nonce: nonce
) { result, error in
self.handleSignInResult(result: result, error: error, resolve: resolve, reject: reject)
}
)
}
}

// MARK: - createAccount

private func createAccount(_ params: [String: Any?]?, promise: Promise) {
@objc func createAccount(_ params: NSDictionary?,
resolve: @escaping RCTPromiseResolveBlock,
reject: @escaping RCTPromiseRejectBlock) {
guard self.clientId != nil else {
promise.reject("NOT_CONFIGURED", "Google Sign-In is not configured. Call configure() first.")
reject("NOT_CONFIGURED", "Google Sign-In is not configured. Call configure() first.", nil)
return
}

guard let presentingVC = self.getPresentingViewController() else {
promise.reject("GOOGLE_SIGN_IN_ERROR", "No presenting view controller available")
return
}
DispatchQueue.main.async {
guard let presentingVC = self.getPresentingViewController() else {
reject("GOOGLE_SIGN_IN_ERROR", "No presenting view controller available", nil)
return
}

let nonce = params?["nonce"] as? String
let nonce = params?["nonce"] as? String

GIDSignIn.sharedInstance.signIn(
withPresenting: presentingVC,
hint: nil,
additionalScopes: nil,
nonce: nonce,
completion: { result, error in
self.handleSignInResult(result: result, error: error, promise: promise)
GIDSignIn.sharedInstance.signIn(
withPresenting: presentingVC,
hint: nil,
additionalScopes: nil,
nonce: nonce
) { result, error in
self.handleSignInResult(result: result, error: error, resolve: resolve, reject: reject)
}
)
}
}

// MARK: - presentExplicitSignIn

private func presentExplicitSignIn(_ params: [String: Any?]?, promise: Promise) {
@objc func presentExplicitSignIn(_ params: NSDictionary?,
resolve: @escaping RCTPromiseResolveBlock,
reject: @escaping RCTPromiseRejectBlock) {
guard self.clientId != nil else {
promise.reject("NOT_CONFIGURED", "Google Sign-In is not configured. Call configure() first.")
reject("NOT_CONFIGURED", "Google Sign-In is not configured. Call configure() first.", nil)
return
}

guard let presentingVC = self.getPresentingViewController() else {
promise.reject("GOOGLE_SIGN_IN_ERROR", "No presenting view controller available")
return
}
DispatchQueue.main.async {
guard let presentingVC = self.getPresentingViewController() else {
reject("GOOGLE_SIGN_IN_ERROR", "No presenting view controller available", nil)
return
}

let nonce = params?["nonce"] as? String
let nonce = params?["nonce"] as? String

GIDSignIn.sharedInstance.signIn(
withPresenting: presentingVC,
hint: nil,
additionalScopes: nil,
nonce: nonce,
completion: { result, error in
self.handleSignInResult(result: result, error: error, promise: promise)
GIDSignIn.sharedInstance.signIn(
withPresenting: presentingVC,
hint: nil,
additionalScopes: nil,
nonce: nonce
) { result, error in
self.handleSignInResult(result: result, error: error, resolve: resolve, reject: reject)
}
)
}
}

// MARK: - signOut

private func signOut(promise: Promise) {
@objc func signOut(_ resolve: @escaping RCTPromiseResolveBlock,
reject: @escaping RCTPromiseRejectBlock) {
GIDSignIn.sharedInstance.signOut()
promise.resolve()
resolve(nil)
}

// MARK: - Helpers
Expand All @@ -159,23 +155,25 @@ public class ClerkGoogleSignInModule: Module {
return topVC
}

private func handleSignInResult(result: GIDSignInResult?, error: Error?, promise: Promise) {
private func handleSignInResult(result: GIDSignInResult?, error: Error?,
resolve: @escaping RCTPromiseResolveBlock,
reject: @escaping RCTPromiseRejectBlock) {
if let error = error {
let nsError = error as NSError

// Check for user cancellation
if nsError.domain == kGIDSignInErrorDomain && nsError.code == GIDSignInError.canceled.rawValue {
promise.reject("SIGN_IN_CANCELLED", "User cancelled the sign-in flow")
reject("SIGN_IN_CANCELLED", "User cancelled the sign-in flow", error)
return
}

promise.reject("GOOGLE_SIGN_IN_ERROR", error.localizedDescription)
reject("GOOGLE_SIGN_IN_ERROR", error.localizedDescription, error)
return
}

guard let result = result,
let idToken = result.user.idToken?.tokenString else {
promise.reject("GOOGLE_SIGN_IN_ERROR", "No ID token received")
reject("GOOGLE_SIGN_IN_ERROR", "No ID token received", nil)
return
}

Expand All @@ -197,6 +195,6 @@ public class ClerkGoogleSignInModule: Module {
] as [String: Any]
]

promise.resolve(response)
resolve(response)
}
}
18 changes: 9 additions & 9 deletions packages/expo/src/specs/NativeClerkGoogleSignIn.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { requireOptionalNativeModule } from 'expo';
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypesNamespace';

type NativeMap = Record<string, unknown>;

interface Spec {
configure(params: NativeMap): void;
signIn(params: NativeMap | null): Promise<NativeMap>;
createAccount(params: NativeMap | null): Promise<NativeMap>;
presentExplicitSignIn(params: NativeMap | null): Promise<NativeMap>;
export interface Spec extends TurboModule {
configure(params: UnsafeObject): void;
signIn(params: UnsafeObject | null): Promise<UnsafeObject>;
createAccount(params: UnsafeObject | null): Promise<UnsafeObject>;
presentExplicitSignIn(params: UnsafeObject | null): Promise<UnsafeObject>;
signOut(): Promise<void>;
}

export default requireOptionalNativeModule<Spec>('ClerkGoogleSignIn');
export default TurboModuleRegistry.get<Spec>('ClerkGoogleSignIn');
Loading