Skip to content

Commit

Permalink
add support for testing sign up
Browse files Browse the repository at this point in the history
  • Loading branch information
rahafjrw committed Dec 2, 2024
1 parent 608a520 commit 98ae917
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Sources/App/Controllers/Manage/SignupController.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Fluent
import Dependencies
import Plot
import Vapor
import SotoCognitoAuthentication
Expand All @@ -13,13 +14,14 @@ enum SignupController {

@Sendable
static func signup(req: Request) async throws -> HTML {
@Dependency(\.cognito) var cognito
struct UserCreds: Content {
var email: String
var password: String
}
do {
let user = try req.content.decode(UserCreds.self)
try await Cognito.signup(req: req, username: user.email, password: user.password)
try await cognito.signup(req: req, username: user.email, password: user.password)
return Verify.View(path: SiteURL.verify.relativeURL(), model: Verify.Model(email: user.email)).document()
} catch let error as AWSErrorType {
let model = Signup.Model(errorMessage: error.message ?? "There was an error.")
Expand Down
4 changes: 3 additions & 1 deletion Sources/App/Core/Dependencies/CognitoClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import Vapor
@DependencyClient
struct CognitoClient {
var authenticate: @Sendable (_ req: Request, _ username: String, _ password: String) async throws -> Void
var signup: @Sendable (_ req: Request, _ username: String, _ password: String) async throws -> Void
}

extension CognitoClient: DependencyKey {
static var liveValue: CognitoClient {
.init(
authenticate: { req, username, password in try await Cognito.authenticate(req: req, username: username, password: password) }
authenticate: { req, username, password in try await Cognito.authenticate(req: req, username: username, password: password) },
signup : { req, username, password in try await Cognito.signup(req: req, username: username, password: password) }
)
}
}
Expand Down

0 comments on commit 98ae917

Please sign in to comment.