@@ -16,23 +16,13 @@ enum LoginController {
1616 @Sendable
1717 static func login( req: Request ) async throws -> Response {
1818 @Dependency ( \. cognito) var cognito
19- let awsClient = AWSClient ( httpClientProvider: . shared( req. application. http. client. shared) )
20- let awsCognitoConfiguration = CognitoConfiguration (
21- userPoolId: Environment . get ( " POOL_ID " ) !,
22- clientId: Environment . get ( " CLIENT_ID " ) !,
23- clientSecret: Environment . get ( " CLIENT_SECRET " ) !,
24- cognitoIDP: CognitoIdentityProvider ( client: awsClient, region: . useast2) ,
25- adminClient: true
26- )
27- req. application. cognito. authenticatable = CognitoAuthenticatable ( configuration: awsCognitoConfiguration)
2819 struct UserCreds : Content {
2920 var email : String
3021 var password : String
3122 }
3223 do {
3324 let user = try req. content. decode ( UserCreds . self)
3425 try await cognito. authenticate ( req: req, username: user. email, password: user. password)
35- try await awsClient. shutdown ( )
3626 return req. redirect ( to: SiteURL . portal. relativeURL ( ) , redirectType: . normal)
3727 } catch let error as SotoCognitoError {
3828 var model = Login . Model ( errorMessage: " There was an error. Please try again. " )
@@ -44,13 +34,10 @@ enum LoginController {
4434 case . invalidPublicKey:
4535 break
4636 }
47- try await awsClient. shutdown ( )
4837 return Login . View ( path: req. url. path, model: model) . document ( ) . encodeResponse ( status: . unauthorized)
4938 } catch let error as AWSClientError {
50- try await awsClient. shutdown ( )
5139 return Login . View ( path: SiteURL . login. relativeURL ( ) , model: Login . Model ( errorMessage: " An AWS client error occurred: \( error. errorCode) " ) ) . document ( ) . encodeResponse ( status: . unauthorized)
5240 } catch {
53- try await awsClient. shutdown ( )
5441 return Login . View ( path: SiteURL . login. relativeURL ( ) , model: Login . Model ( errorMessage: " An unknown error occurred: \( error. localizedDescription) " ) ) . document ( ) . encodeResponse ( status: . unauthorized)
5542 }
5643
0 commit comments