SupabaseS
Supabase11mo ago
Alex

[Swift] Sign In With Apple, anon users, & linkIdentity

Hi team! Lets say I create an iOS app where the default user is signed in anonymously on launch via:

let session = try await supabase.auth.signInAnonymously(
data: [                                  "appleIdentifierForVendor": .string(appleDeviceID)])


At some point later, the user wants to make an account. How do I present them a SignInWithApple auth in SwiftUI? The try await client.auth.linkIdentity(provider: .apple) doesn't seem to take an Auth token for the payload / seems to try to direct to a URL so I'm not sure how I'd make use of it.

        do {
            guard
                let credential = try result.get().credential
                    as? ASAuthorizationAppleIDCredential
            else {
                logger.error("Error signing in with Apple: No credential")
                return
            }

            guard
                let idToken = credential.identityToken
                    .flatMap({ String(data: $0, encoding: .utf8) })
            else {
                logger.error("Error signing in with Apple: No idToken")
                return
            }

            //Convert from anonymous user, but this tries to open a URL or something instead of using the auth token?
            try await client.auth.linkIdentity(provider: .apple)


            // This is how we'd sign in normally if there wasn't an anonymous user we wanted to link
            //            try await client.auth.signInWithIdToken(
            //                credentials: .init(
            //                    provider: .apple,
            //                    idToken: idToken
            //                )
            //            )


Could someone assist? Thank you so much
Was this page helpful?