diff --git a/Prisma/Onboarding/AccountOnboarding.swift b/Prisma/Onboarding/AccountOnboarding.swift index 4efef49..731acea 100644 --- a/Prisma/Onboarding/AccountOnboarding.swift +++ b/Prisma/Onboarding/AccountOnboarding.swift @@ -13,6 +13,7 @@ import SwiftUI struct AccountOnboarding: View { @Environment(Account.self) private var account + @Environment(PrismaStandard.self) private var standard @Environment(OnboardingNavigationPath.self) private var onboardingNavigationPath @@ -21,6 +22,7 @@ struct AccountOnboarding: View { Task { // Placing the nextStep() call inside this task will ensure that the sheet dismiss animation is // played till the end before we navigate to the next step. + await standard.setAccountTimestamp() onboardingNavigationPath.nextStep() } } header: { diff --git a/Prisma/Standard/PrismaStandard.swift b/Prisma/Standard/PrismaStandard.swift index 29f45ef..0f593db 100644 --- a/Prisma/Standard/PrismaStandard.swift +++ b/Prisma/Standard/PrismaStandard.swift @@ -174,6 +174,19 @@ actor PrismaStandard: Standard, EnvironmentAccessible, HealthKitConstraint, Onbo } try await accountStorage.create(identifier, details) } + + func setAccountTimestamp() async { + // Add a "created_at" timestamp to the newly created user document + let timestamp = Timestamp(date: Date()) + do { + try await self.userDocumentReference.setData([ + "created_at": timestamp + ], merge: true) + print("Added timestamp to user document") + } catch { + print("Error updating document: \(error)") + } + } func load(_ identifier: AdditionalRecordId, _ keys: [any AccountKey.Type]) async throws -> PartialAccountDetails { guard let accountStorage else {