Last active
November 17, 2021 11:02
-
-
Save nicnocquee/f0a0dbe345f0a18a378d9022c7d11e9c 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 RegisterRequestData: Encodable { | |
let username: String | |
let email: String | |
let password: String | |
} | |
struct LoginResponseData: Decodable { | |
let jwt: String | |
} | |
func register(_ registerRequest: RegisterRequestData) async throws -> String { | |
// URLSession.shared.post is an extension which you can find here https://gist.github.com/nicnocquee/f0a0dbe345f0a18a378d9022c7d11e9c#gistcomment-3964831 | |
let registerData: LoginResponseData = try await URLSession.shared.post(pathname: "/auth/local/register", data: registerRequest) | |
return registerData.jwt | |
} | |
// somewhere else | |
Task { | |
let registerJwt = try await register(RegisterRequestData(username: "your username", email: "your email", password: "your pssword")) | |
// use the jwt in other API calls | |
print(registerJwt) | |
} |
Author
nicnocquee
commented
Nov 16, 2021
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment