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

New Auth Flow with Firebase Functions Submodule #92

Merged
merged 62 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
4f50c64
Bump SpeziFirebase and SpeziAccount
Supereg Sep 1, 2024
5b493e6
Minor changes
Supereg Sep 2, 2024
38ee276
Add firebase submodule
nriedman Sep 3, 2024
fdf2f15
Update build-and-test.yml
nriedman Sep 3, 2024
9590ab5
Create .gitmodules.license
nriedman Sep 3, 2024
b4a2b10
fix typo in Install Dependencies
nriedman Sep 3, 2024
46e87b1
Update build-and-test.yml
nriedman Sep 3, 2024
59aebcc
Update build-and-test.yml
nriedman Sep 3, 2024
5a83a27
Update build-and-test.yml
nriedman Sep 3, 2024
d2f815b
Change invitation code in setupTestEnvironment
nriedman Sep 3, 2024
c7e1251
Start testing, get rid of deprecated firebase
nriedman Sep 3, 2024
078223b
use path to submodule's firebase.json
nriedman Sep 3, 2024
f45b4ed
Adapt
pauljohanneskraft Sep 3, 2024
b2f3d20
messages UI testing
nriedman Sep 3, 2024
aeeaf2a
Fix testing
nriedman Sep 3, 2024
6ddd659
Don't expect initial value in notification settings
nriedman Sep 4, 2024
b82ca00
Clear managers on sign out
nriedman Sep 4, 2024
d5ab406
Don't use changes from .github branch
nriedman Sep 4, 2024
43ea04d
Use custom command for firebase setup and fastlane tests
nriedman Sep 4, 2024
183993a
Linting, notification settings UI Tests
nriedman Sep 4, 2024
0302f7b
Uncomment out unregister device token
nriedman Sep 4, 2024
4caeda6
Don't validate arrival on goTo testing helper function
nriedman Sep 4, 2024
95ecdc5
Fix testing bug
nriedman Sep 4, 2024
ce5dc0b
Remove unregisterDeviceToken call on sign out
nriedman Sep 4, 2024
021d5f0
Revert "Fix testing bug"
nriedman Sep 4, 2024
599b4d8
Revert "Don't validate arrival on goTo testing helper function"
nriedman Sep 4, 2024
72f03cb
Update AddMeasurementUITests.swift
nriedman Sep 4, 2024
602662d
Remove conflicting invitation code in tests
nriedman Sep 4, 2024
78e136e
styling
nriedman Sep 4, 2024
50cff22
Stall for 5 seconds at beginning of every test
nriedman Sep 4, 2024
680734b
Pass password as argument in OnboardingTests
nriedman Sep 4, 2024
19a7d58
update vitals descriptions
nriedman Sep 5, 2024
baf9852
Try a different way of finding the button.
nriedman Sep 5, 2024
11b1d98
swipe up in ui test because xctest can't find the button
nriedman Sep 5, 2024
49a332b
Wait longer before starting testInAppLogon
nriedman Sep 5, 2024
33e5869
Test commenting out the testInAppLogon
nriedman Sep 5, 2024
aa7267e
Change workflow to use fastlane test job with imported emulator
nriedman Sep 5, 2024
5ba037c
Un-comment out testInAppLogon
nriedman Sep 5, 2024
3a79d7f
Don't disable sheet with setupTestEnvironment flag
nriedman Sep 5, 2024
ac079df
Reverse changes to dependencies
pauljohanneskraft Sep 5, 2024
13957be
Reverse changes to package.resolved
pauljohanneskraft Sep 5, 2024
0a1c230
Rewrite auth flow, get organization id and notification settings from…
pauljohanneskraft Sep 12, 2024
392c63c
Specify one branch
pauljohanneskraft Sep 12, 2024
8def9bc
Update ENGAGE-HF-Firebase
pauljohanneskraft Sep 12, 2024
f87f518
Merge branch 'fix/add-submodule' into feature/new-auth-flow-with-subm…
pauljohanneskraft Sep 12, 2024
16d7c1b
Fix tests
pauljohanneskraft Sep 12, 2024
aec14aa
Remove unnecessary mapping
pauljohanneskraft Sep 12, 2024
fabf8a9
Update emulators to branch
pauljohanneskraft Sep 13, 2024
02f3037
Update submodule from setup-user branch
pauljohanneskraft Sep 13, 2024
0f54b7e
Simplify command and fix test
pauljohanneskraft Sep 13, 2024
953b893
Fix command
pauljohanneskraft Sep 13, 2024
ac65bba
Only ever use test credentials
pauljohanneskraft Sep 13, 2024
24c7007
Reference newest commit
pauljohanneskraft Sep 13, 2024
612fe96
Set SpeziAccount and SpeziFirebase to new betas
pauljohanneskraft Sep 15, 2024
8150ad5
Update SpeziFirebase & SpeziAccount
pauljohanneskraft Sep 15, 2024
513edf8
Make accountKeys optional
pauljohanneskraft Sep 15, 2024
46d4ea8
Make sure github workflows are not set towards branches
pauljohanneskraft Sep 16, 2024
8813d3e
Update Firebase submodule
pauljohanneskraft Sep 16, 2024
b01123e
Specify main branch for Firebase submodule
pauljohanneskraft Sep 16, 2024
018fa17
Fix password for login test
pauljohanneskraft Sep 16, 2024
e2ccd99
Wait a little longer for the home page to appear, should make tests l…
pauljohanneskraft Sep 16, 2024
a2c9a37
force refresh token after enrollUser
pauljohanneskraft Sep 16, 2024
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
5 changes: 0 additions & 5 deletions .firebaserc

This file was deleted.

5 changes: 0 additions & 5 deletions .firebaserc.license

This file was deleted.

5 changes: 4 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ jobs:
with:
artifactname: ENGAGEHF.xcresult
runsonlabels: '["macOS", "self-hosted"]'
setupfirebaseemulator: true
fastlanelane: test
firebaseemulatorimport: ./firebase
firebasejsonpath: ./ENGAGE-HF-Firebase/firebase.json
setupfirebaseemulator: true
checkout_submodules: true
customcommand: npm --prefix ENGAGE-HF-Firebase run prepare && firebase emulators:exec -c ./ENGAGE-HF-Firebase/firebase.json --export-on-exit=./firebase 'npm --prefix ./ENGAGE-HF-Firebase/functions run serve:seed'
secrets:
GOOGLE_APPLICATION_CREDENTIALS_BASE64: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_BASE64 }}
uploadcoveragereport:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ENGAGE-HF-Firebase"]
path = ENGAGE-HF-Firebase
url = https://github.com/StanfordBDHG/ENGAGE-HF-Firebase.git
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
This source file is part of the ENGAGE-HF project based on the Stanford Spezi Template Application project

SPDX-FileCopyrightText: 2023 Stanford University
SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md)

SPDX-License-Identifier: MIT
1 change: 1 addition & 0 deletions ENGAGE-HF-Firebase
Submodule ENGAGE-HF-Firebase added at cc09c8
108 changes: 80 additions & 28 deletions ENGAGEHF.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
{
"identity" : "fhirmodels",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/FHIRModels.git",
"location" : "https://github.com/apple/FHIRModels",
"state" : {
"revision" : "861afd5816a98d38f86220eab2f812d76cad84a0",
"version" : "0.5.0"
Expand All @@ -60,8 +60,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk.git",
"state" : {
"revision" : "9118aca998dbe2ceac45d64b21a91c6376928df7",
"version" : "11.1.0"
"revision" : "1fc52ab0e172e7c5a961f975a76c2611f4f22852",
"version" : "11.2.0"
}
},
{
Expand Down Expand Up @@ -114,8 +114,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordBDHG/HealthKitOnFHIR.git",
"state" : {
"revision" : "c24e316311ff9813cb1fe32cd8820bcca6e5e7f2",
"version" : "0.2.10"
"revision" : "87a9257e6fa37407f3437e4a0bf21dd09a4ea7c5",
"version" : "0.2.11"
}
},
{
Expand Down Expand Up @@ -195,8 +195,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziAccount.git",
"state" : {
"revision" : "6b1603d2dd95b1787cfb0cbdce32a4b4bebb79ae",
"version" : "2.0.0-beta.5"
"revision" : "397a55a7b0f108088d3db510ee48fc974a322c87",
"version" : "2.0.0-beta.8"
}
},
{
Expand All @@ -222,17 +222,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziDevices.git",
"state" : {
"revision" : "cfba7691b6211bb2f566a8c263ff973921ee555b",
"version" : "1.2.2"
"revision" : "dc8dcd53773b9bb4041870b0f65cec32f7ed5108",
"version" : "1.3.0"
}
},
{
"identity" : "spezifirebase",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziFirebase.git",
"state" : {
"revision" : "12e7b779a3339737ea100b4eb7491072d4e83cd5",
"version" : "2.0.0-beta.2"
"revision" : "5aae93f567091b29f7683863baa2241f7c95290d",
"version" : "2.0.0-beta.4"
}
},
{
Expand Down Expand Up @@ -328,7 +328,7 @@
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "9bf03ff58ce34478e66aaee630e491823326fd06",
"version" : "1.1.3"
Expand All @@ -339,17 +339,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "4c4453b489cf76e6b3b0f300aba663eb78182fad",
"version" : "2.70.0"
"revision" : "9746cf80e29edfef2a39924a66731249223f42a3",
"version" : "2.72.0"
}
},
{
"identity" : "swift-package-list",
"kind" : "remoteSourceControl",
"location" : "https://github.com/FelixHerrmann/swift-package-list",
"state" : {
"revision" : "01f2e9860c122dd8c3ae2a7e642b85bbb053efe3",
"version" : "4.2.0"
"revision" : "60b77bea44f5b2f7369aecfcd993f7672e09602a",
"version" : "4.3.0"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions ENGAGEHF.xcodeproj/xcshareddata/xcschemes/ENGAGEHF.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@
</CommandLineArgument>
<CommandLineArgument
argument = "--assumeOnboardingComplete"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "--setupTestEnvironment"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "--testMockDevices"
Expand Down
58 changes: 0 additions & 58 deletions ENGAGEHF/Account/AccountSetupSheet.swift

This file was deleted.

39 changes: 3 additions & 36 deletions ENGAGEHF/Account/AccountSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,17 @@
// SPDX-License-Identifier: MIT
//

import FirebaseFunctions
@_spi(TestingSupport) import SpeziAccount
import SpeziLicense
import SwiftUI


struct AccountSheet: View {
@Environment(\.dismiss) var dismiss

@Environment(Account.self) private var account
@Environment(\.accountRequired) var accountRequired

@State var isInSetup = false


var body: some View {
NavigationStack {
ZStack {
if account.signedIn && !isInSetup {
AccountOverview(close: .showCloseButton, deletion: .disabled) {
AdditionalAccountSections()
}
} else {
AccountSetup { _ in
dismiss() // we just signed in, dismiss the account setup sheet
} header: {
AccountSetupHeader()
}
.onAppear {
isInSetup = true
}
.toolbar {
if !accountRequired {
closeButton
}
}
}
}
}
}

var closeButton: some ToolbarContent {
ToolbarItem(placement: .cancellationAction) {
Button("CLOSE") {
dismiss()
AccountOverview(close: .showCloseButton, deletion: .disabled) {
AdditionalAccountSections()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ENGAGEHF/Account/AdditionalAccountSections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SpeziDevicesUI
import SpeziLicense
import SwiftUI


struct AdditionalAccountSections: View {
var body: some View {
Section {
Expand Down
51 changes: 12 additions & 39 deletions ENGAGEHF/Account/InvitationCodeModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Firebase
import FirebaseAuth
import FirebaseFunctions
import Spezi
import SpeziAccount
Expand All @@ -27,50 +28,23 @@
}
}

func clearAccount() async {
do {
try await signOutAccount()
} catch {
logger.debug("Failed to sing out firebase account: \(error)")
}
}

func signOutAccount() async throws {
do {
try await accountService?.logout()
} catch FirebaseAccountError.notSignedIn {
// do nothing
} catch {
throw error
}
}

func verifyOnboardingCode(_ invitationCode: String) async throws {
do {
if FeatureFlags.disableFirebase {
guard invitationCode == "ENGAGEHFTEST1" else {
throw InvitationCodeError.invitationCodeInvalid
}

Check warning on line 37 in ENGAGEHF/Account/InvitationCodeModule.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Account/InvitationCodeModule.swift#L37

Added line #L37 was not covered by tests
try? await Task.sleep(for: .seconds(0.25))
} else {
guard let accountService else {
preconditionFailure("The Firebase Account Service was not present even though `disableFirebase` was turned off!")
}

try await signOutAccount()
try await accountService.signUpAnonymously()

let checkInvitationCode = Functions.functions().httpsCallable("checkInvitationCode")

do {
_ = try await checkInvitationCode.call(
[
"invitationCode": invitationCode
]
)
logger.debug("About to enroll user")
let enrollUser = Functions.functions().httpsCallable("enrollUser")
_ = try await enrollUser.call(["invitationCode": invitationCode])
_ = try? await Auth.auth().currentUser?.getIDToken(forcingRefresh: true)
logger.debug("Successfully enrolled user!")
} catch {
logger.error("Failed to check invitation code: \(error)")
logger.error("Failed to enroll user: \(error)")

Check warning on line 47 in ENGAGEHF/Account/InvitationCodeModule.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Account/InvitationCodeModule.swift#L47

Added line #L47 was not covered by tests
throw InvitationCodeError.invitationCodeInvalid
}
}
Expand Down Expand Up @@ -114,20 +88,19 @@
try await accountService.login(userId: email, password: password)
return // account was already established previously
} catch FirebaseAccountError.invalidCredentials {
// probably doesn't exists. We try to create a new one below
// probably doesn't exist. We try to create a new one below
} catch {
logger.error("Failed logging into test account: \(error)")
return
throw error

Check warning on line 94 in ENGAGEHF/Account/InvitationCodeModule.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Account/InvitationCodeModule.swift#L94

Added line #L94 was not covered by tests
}

try await verifyOnboardingCode(invitationCode)


do {
var details = AccountDetails()
details.userId = email
details.password = password
details.name = PersonNameComponents(givenName: "Leland", familyName: "Stanford")
try await accountService.signUp(with: details)
try await verifyOnboardingCode(invitationCode)

Check warning on line 103 in ENGAGEHF/Account/InvitationCodeModule.swift

View check run for this annotation

Codecov / codecov/patch

ENGAGEHF/Account/InvitationCodeModule.swift#L103

Added line #L103 was not covered by tests
} catch {
logger.error("Failed setting up test account : \(error)")
throw error
Expand Down
Loading
Loading