Skip to content

Commit

Permalink
Enable Invitation Code Validation using Firebase Cloud Functions (#5)
Browse files Browse the repository at this point in the history
# Enable Invitation Code Validation using Firebase Cloud Functions

## ⚙️ Release Notes 
- Enable Invitation Code Validation using Firebase Cloud Functions


## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
PSchmiedmayer authored Mar 11, 2024
1 parent f078a9b commit 4f5e88d
Show file tree
Hide file tree
Showing 36 changed files with 7,141 additions and 923 deletions.
1 change: 1 addition & 0 deletions .github/workflows/beta-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
permissions:
contents: read
with:
runsonlabels: '["macOS", "self-hosted"]'
googleserviceinfoplistpath: 'StudyApplication/Supporting Files/GoogleService-Info.plist'
setupsigning: true
fastlanelane: beta
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
runsonlabels: '["macOS", "self-hosted"]'
setupSimulators: true
setupfirebaseemulator: true
customcommand: "firebase emulators:exec 'fastlane test'"
customcommand: "npm install --prefix ./functions && firebase emulators:exec 'fastlane test'"
uploadcoveragereport:
name: Upload Coverage Report
needs: buildandtest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SPDX-License-Identifier: MIT
This repository contains the StudyApplication.
The StudyApplication is using the [Spezi](https://github.com/StanfordSpezi/Spezi) ecosystem and builds on top of the [Stanford Spezi Template Application](https://github.com/StanfordSpezi/SpeziTemplateApplication).

> [!NOTE] 
> [!NOTE]
> Do you want to learn more about the Stanford Spezi Template Application and how to use, extend, and modify this application? Check out the [Stanford Spezi Template Application documentation](https://stanfordspezi.github.io/SpeziTemplateApplication)

Expand Down
80 changes: 30 additions & 50 deletions StudyApplication.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "2b0be697894fe4a23f5fcde7d3c351be071985722bbb06b21a19e8a9196299a9",
"originHash" : "0234cf36595d6a5fc4bf3c54942b170bdbefd26ef609a4d8a651f17037d3face",
"pins" : [
{
"identity" : "abseil-cpp-binary",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<CommandLineArguments>
<CommandLineArgument
argument = "--disableFirebase"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "--showOnboarding"
Expand All @@ -89,10 +89,6 @@
argument = "--skipOnboarding"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "--testSchedule"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "--useFirebaseEmulator"
isEnabled = "NO">
Expand Down
38 changes: 0 additions & 38 deletions StudyApplication/Account/AccountButton.swift

This file was deleted.

43 changes: 0 additions & 43 deletions StudyApplication/Account/AccountSetupHeader.swift

This file was deleted.

91 changes: 0 additions & 91 deletions StudyApplication/Account/AccountSheet.swift

This file was deleted.

35 changes: 35 additions & 0 deletions StudyApplication/Firebase/FirebaseAccountConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// This source file is part of the StudyApplication based on the Stanford Spezi Template Application project
//
// SPDX-FileCopyrightText: 2023 Stanford University
//
// SPDX-License-Identifier: MIT
//

import Spezi
import class FirebaseAuth.Auth
import SpeziFirebaseConfiguration


/// Module to configure firebase auth for anonumous authentication.
final class FirebaseAccountConfiguration: Module {
@Dependency private var configureFirebaseApp: ConfigureFirebaseApp

private let emulatorSettings: (host: String, port: Int)?


/// - Parameters:
/// - emulatorSettings: The emulator settings. The default value is `nil`, connecting the FirebaseAccount module to the Firebase Auth cloud instance.
init(
emulatorSettings: (host: String, port: Int)? = nil
) {
self.emulatorSettings = emulatorSettings
}


func configure() {
if let emulatorSettings {
Auth.auth().useEmulator(withHost: emulatorSettings.host, port: emulatorSettings.port)
}
}
}
35 changes: 35 additions & 0 deletions StudyApplication/Firebase/FirebaseFunctionsConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// This source file is part of the StudyApplication based on the Stanford Spezi Template Application project
//
// SPDX-FileCopyrightText: 2023 Stanford University
//
// SPDX-License-Identifier: MIT
//

import FirebaseFunctions
import Spezi
import SpeziFirebaseConfiguration


/// Module to configure Firebase Functions
final class FirebaseFunctionsConfiguration: Module {
@Dependency private var configureFirebaseApp: ConfigureFirebaseApp

private let emulatorSettings: (host: String, port: Int)?


/// - Parameters:
/// - emulatorSettings: The emulator settings. The default value is `nil`, connecting the FirebaseFunctions module to the Firebase Functions cloud instance.
init(
emulatorSettings: (host: String, port: Int)? = nil
) {
self.emulatorSettings = emulatorSettings
}


func configure() {
if let emulatorSettings {
Functions.functions().useEmulator(withHost: emulatorSettings.host, port: emulatorSettings.port)
}
}
}
24 changes: 1 addition & 23 deletions StudyApplication/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// SPDX-License-Identifier: MIT
//

import SpeziAccount
import SwiftUI


Expand Down Expand Up @@ -39,33 +38,12 @@ struct HomeView: View {
Label("Tasks", systemImage: "checklist")
}
}
.sheet(isPresented: $presentingAccount) {
AccountSheet()
}
.verifyRequiredAccountDetails(Self.accountEnabled)
}
}


#if DEBUG
#Preview {
let details = AccountDetails.Builder()
.set(\.userId, value: "lelandstanford@stanford.edu")
.set(\.name, value: PersonNameComponents(givenName: "Leland", familyName: "Stanford"))

return HomeView()
.previewWith(standard: StudyApplicationStandard()) {
AccountConfiguration(building: details, active: MockUserIdPasswordAccountService())
}
}

#Preview {
CommandLine.arguments.append("--disableFirebase")
return HomeView()
.previewWith(standard: StudyApplicationStandard()) {
AccountConfiguration {
MockUserIdPasswordAccountService()
}
}
HomeView()
}
#endif
Loading

0 comments on commit 4f5e88d

Please sign in to comment.