Add minimal sign-in page
This commit is contained in:
1 parent
36f2b2d843
commit
13d8597eea
4 files changed
+228
-15
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import Combine
|
||||
|
||||
@MainActor
|
||||
final class AuthSessionStore: ObservableObject {
|
||||
enum State {
|
||||
case checking
|
||||
case signedOut
|
||||
case signedIn
|
||||
}
|
||||
|
||||
@Published private(set) var state: State = .checking
|
||||
@Published private(set) var isSigningIn = false
|
||||
|
||||
private let api = MusicAPI()
|
||||
|
||||
func restoreSession() async {
|
||||
guard state == .checking else { return }
|
||||
|
||||
do {
|
||||
state = try await api.sessionStatus().authenticated ? .signedIn : .signedOut
|
||||
} catch {
|
||||
state = .signedOut
|
||||
}
|
||||
}
|
||||
|
||||
func signIn(email: String, password: String) async throws {
|
||||
isSigningIn = true
|
||||
defer { isSigningIn = false }
|
||||
|
||||
try await api.signIn(email: email, password: password)
|
||||
state = .signedIn
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user