Fix: Handle sign-up without household data
Make household optional in AuthResponse since new users don't have a household yet. Skip passkey setup and WebSocket connection until user creates or joins a household.
This commit is contained in:
parent
440d668d2c
commit
3421d35c0e
3 changed files with 13 additions and 10 deletions
Binary file not shown.
Binary file not shown.
|
|
@ -168,19 +168,22 @@ class AppState: ObservableObject {
|
|||
self.currentUser = authData.user
|
||||
self.currentHousehold = authData.household
|
||||
try await cacheManager.cacheUser(authData.user)
|
||||
try await cacheManager.cacheHousehold(authData.household)
|
||||
self.isAuthenticated = true
|
||||
|
||||
if let household = authData.household {
|
||||
try await cacheManager.cacheHousehold(household)
|
||||
await webSocketManager.connect(
|
||||
householdId: authData.household.id,
|
||||
householdId: household.id,
|
||||
userId: authData.user.id,
|
||||
baseURL: serverURL
|
||||
)
|
||||
}
|
||||
self.isAuthenticated = true
|
||||
|
||||
// Set token in PasskeyHelper and initiate passkey setup
|
||||
// Set token in PasskeyHelper and setup passkey if household exists
|
||||
PasskeyHelper.shared.setAuthToken(authData.session.token)
|
||||
if authData.household != nil {
|
||||
try await setupPasskey()
|
||||
}
|
||||
}
|
||||
|
||||
func createHousehold(name: String) async throws {
|
||||
isLoading = true
|
||||
|
|
@ -294,7 +297,7 @@ struct SignInPayload: Codable {
|
|||
|
||||
struct AuthResponse: Codable {
|
||||
let user: User
|
||||
let household: Household
|
||||
let household: Household?
|
||||
let session: Session
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue