supabase-community / gotrue-swift

A Swift client library for GoTrue.
MIT License
36 stars 31 forks source link

Add sign in with OpenIDConnectCredentials to the client. #43

Closed SquaredLab closed 1 year ago

SquaredLab commented 1 year ago

It would be very handy to have in the client a public method for signing in with OpenIDConnectCredentials in order to accomplish the Apple Sign In flow.

Here is the code of the function:

@discardableResult 
public func signIn(credential: OpenIDConnectCredentials) async throws -> Session 
{
    let session = try await Env.client.send(
        Paths.token.post(
        grantType: .idToken,
        .openIDConnectCredentials(credential)
    )).value    
    if session.user.confirmedAt != nil 
    {
        try await Env.sessionManager.update(session)
        authEventChangeContinuation.yield(.signedIn)
    }
    return session
}