Skip to content

Commit 608a520

Browse files
committed
separate cognito sign up function
1 parent 803cd82 commit 608a520

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Sources/App/Controllers/Manage/Cognito.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,19 @@ struct Cognito {
2525
}
2626
try awsClient.syncShutdown()
2727
}
28+
29+
@Sendable
30+
static func signup(req: Request, username: String, password: String) async throws {
31+
let awsClient = AWSClient(httpClientProvider: .shared(req.application.http.client.shared))
32+
let awsCognitoConfiguration = CognitoConfiguration(
33+
userPoolId: Environment.get("POOL_ID")!,
34+
clientId: Environment.get("CLIENT_ID")!,
35+
clientSecret: Environment.get("CLIENT_SECRET")!,
36+
cognitoIDP: CognitoIdentityProvider(client: awsClient, region: .useast2),
37+
adminClient: true
38+
)
39+
req.application.cognito.authenticatable = CognitoAuthenticatable(configuration: awsCognitoConfiguration)
40+
try await req.application.cognito.authenticatable.signUp(username: username, password: password, attributes: [:], on:req.eventLoop)
41+
try awsClient.syncShutdown()
42+
}
2843
}

Sources/App/Controllers/Manage/SignupController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ enum SignupController {
1717
var email: String
1818
var password: String
1919
}
20-
let user = try req.content.decode(UserCreds.self)
2120
do {
22-
let _ = try await req.application.cognito.authenticatable.signUp(username: user.email, password: user.password, attributes: [:], on:req.eventLoop)
21+
let user = try req.content.decode(UserCreds.self)
22+
try await Cognito.signup(req: req, username: user.email, password: user.password)
2323
return Verify.View(path: SiteURL.verify.relativeURL(), model: Verify.Model(email: user.email)).document()
2424
} catch let error as AWSErrorType {
2525
let model = Signup.Model(errorMessage: error.message ?? "There was an error.")

0 commit comments

Comments
 (0)