From 3226bad11f8a4945577cd5127673ad61d881eb94 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Sun, 10 Mar 2024 12:21:47 -0700 Subject: [PATCH] Helpers for invitation codes --- PAWS/PAWSStandard.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/PAWS/PAWSStandard.swift b/PAWS/PAWSStandard.swift index a8fd3da3..a4810ccd 100644 --- a/PAWS/PAWSStandard.swift +++ b/PAWS/PAWSStandard.swift @@ -60,6 +60,12 @@ actor PAWSStandard: Standard, EnvironmentAccessible, HealthKitConstraint, Onboar return Storage.storage().reference().child("users/\(details.accountId)") } } + + private var invitationBucketReference: StorageReference { + get async throws { + Storage.storage().reference().child("invitations") + } + } init() { @@ -182,6 +188,20 @@ actor PAWSStandard: Standard, EnvironmentAccessible, HealthKitConstraint, Onboar .collection("HealthKit") // Add all HealthKit sources in a /HealthKit collection. .document(uuid.uuidString) // Set the document identifier to the UUID of the document. } + + private func invitationCodeIsValid(_ invitationCode: String) async -> Bool { + guard let validInvitationCodes = try? await invitationBucketReference.listAll() else { + return false + } + + for item in validInvitationCodes.items { + if (try? await item.data(maxSize: 128).base64EncodedString()) == invitationCode { + return true + } + } + + return false + } func deletedAccount() async throws { // delete all user associated data