ยฉ 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabaseโ€ข13mo agoโ€ข
1 reply
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)])
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
            //                )
            //            )
        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
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Sign in With Apple for Swift
SupabaseSSupabase / help-and-questions
4y ago
Swift Auth SDK & Sign in with Apple Refresh Tokens
SupabaseSSupabase / help-and-questions
6mo ago
Apple Sign In
SupabaseSSupabase / help-and-questions
8mo ago
Apple sign-in issue
SupabaseSSupabase / help-and-questions
3mo ago