Last active
November 16, 2021 23:56
-
-
Save nicnocquee/446f9ec7365a728348838a7865d0f142 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
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