Skip to content

Commit 98ae917

Browse files
committed
add support for testing sign up
1 parent 608a520 commit 98ae917

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Sources/App/Controllers/Manage/SignupController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Fluent
2+
import Dependencies
23
import Plot
34
import Vapor
45
import SotoCognitoAuthentication
@@ -13,13 +14,14 @@ enum SignupController {
1314

1415
@Sendable
1516
static func signup(req: Request) async throws -> HTML {
17+
@Dependency(\.cognito) var cognito
1618
struct UserCreds: Content {
1719
var email: String
1820
var password: String
1921
}
2022
do {
2123
let user = try req.content.decode(UserCreds.self)
22-
try await Cognito.signup(req: req, username: user.email, password: user.password)
24+
try await cognito.signup(req: req, username: user.email, password: user.password)
2325
return Verify.View(path: SiteURL.verify.relativeURL(), model: Verify.Model(email: user.email)).document()
2426
} catch let error as AWSErrorType {
2527
let model = Signup.Model(errorMessage: error.message ?? "There was an error.")

Sources/App/Core/Dependencies/CognitoClient.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ import Vapor
1919
@DependencyClient
2020
struct CognitoClient {
2121
var authenticate: @Sendable (_ req: Request, _ username: String, _ password: String) async throws -> Void
22+
var signup: @Sendable (_ req: Request, _ username: String, _ password: String) async throws -> Void
2223
}
2324

2425
extension CognitoClient: DependencyKey {
2526
static var liveValue: CognitoClient {
2627
.init(
27-
authenticate: { req, username, password in try await Cognito.authenticate(req: req, username: username, password: password) }
28+
authenticate: { req, username, password in try await Cognito.authenticate(req: req, username: username, password: password) },
29+
signup : { req, username, password in try await Cognito.signup(req: req, username: username, password: password) }
2830
)
2931
}
3032
}

0 commit comments

Comments
 (0)