Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gotrue): AuthResponse return non-optional user #174

Merged
merged 1 commit into from
Dec 5, 2023
Merged
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
11 changes: 0 additions & 11 deletions Sources/GoTrue/Extensions.swift

This file was deleted.

12 changes: 12 additions & 0 deletions Sources/GoTrue/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,18 @@ public enum AuthResponse: Codable, Hashable, Sendable {
case let .user(value): try container.encode(value)
}
}

public var user: User {
switch self {
case let .session(session): return session.user
case let .user(user): return user
}
}

public var session: Session? {
if case let .session(session) = self { return session }
return nil
}
}

public struct UserAttributes: Codable, Hashable, Sendable {
Expand Down
16 changes: 16 additions & 0 deletions Tests/GoTrueTests/AuthResponseTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import GoTrue
import SnapshotTesting
import XCTest

final class AuthResponseTests: XCTestCase {
func testSession() throws {
let response = try JSONDecoder.goTrue.decode(AuthResponse.self, from: json(named: "session"))
XCTAssertNotNil(response.session)
XCTAssertEqual(response.user, response.session?.user)
}

func testUser() throws {
let response = try JSONDecoder.goTrue.decode(AuthResponse.self, from: json(named: "user"))
XCTAssertNil(response.session)
}
}
19 changes: 0 additions & 19 deletions Tests/GoTrueTests/DecoderTests.swift

This file was deleted.