-
-
Save cardoso/e56af370f49f9e623574a4443394754b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AWSLambdaEvents | |
import AWSLambdaRuntime | |
import SwiftJWT | |
import Foundation | |
Lambda.run { (context: Lambda.Context, event: APIGateway.Request, callback: @escaping (Result<APIGateway.Response, Error>) -> Void) in | |
guard | |
let bodyData = event.body?.data(using: .utf8), | |
let json = try? JSONSerialization.jsonObject(with: bodyData, options: []) as? [String: Any], | |
let userId = json["user_id"] as? String | |
else { | |
callback(.success(APIGateway.Response(statusCode: .badRequest))) | |
return | |
} | |
if let jwt = try? generateJWT(for: userId) { | |
callback(.success(APIGateway.Response(statusCode: .ok, body: jwt))) | |
} else { | |
callback(.success(.init(statusCode: .internalServerError))) | |
} | |
} | |
func generateJWT(for userId: String) throws -> String { | |
return "" // TODO: Generate JWT | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment