Skip to content

Instantly share code, notes, and snippets.

@nicnocquee
Last active November 16, 2021 23:56
Show Gist options
  • Save nicnocquee/446f9ec7365a728348838a7865d0f142 to your computer and use it in GitHub Desktop.
Save nicnocquee/446f9ec7365a728348838a7865d0f142 to your computer and use it in GitHub Desktop.
struct LoginRequestData: Encodable {
let identifier: String
let password: String
}
struct LoginResponseData: Decodable {
let jwt: String
}
func login(_ loginRequest: LoginRequestData) async throws -> String {
// URLSession.shared.post is an extension which you can find here https://gist.github.com/nicnocquee/f0a0dbe345f0a18a378d9022c7d11e9c#gistcomment-3964831
let loginData: LoginResponseData = try await URLSession.shared.post(pathname: "/auth/local", data: loginRequest)
return loginData.jwt
}
Task {
let jwt = try await login(LoginRequestData(identifier: "your email", password: "password here"))
print(jwt)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment