Email And Password
Allow users to sign up with email and password in your App.
Sign up a new user
To register a new user with email and password:
Usage
func signUp() async {
do {
let result = try await OFSDK.shared.signUpWith(params: OFSignUpWithEmailPasswordParams(email: email, password: password, options: OFSignUpWithEmailPasswordOptionsParams(data: ["name": "\(firstName) \(lastName)"])))
if let action = result?.action, action == "verify_email" {
try await verifyEmail()
toast("Email verification sent! Check your email.")
return
}
} catch {
toast("Failed to sign up: \(error)")
}
}
func verifyEmail() async throws {
try await OFSDK.shared.requestEmailVerification(params: OFRequestEmailVerificationParams(email: email, redirectUrl: "YOUR_REDIRECT_URL"))
}Parameters
struct OFSignUpWithEmailPasswordParams: OFCodableSendable {
public let email: String
public let password: String
public let options: OFSignUpWithEmailPasswordOptionsParams?
public let ecosystemGame: String?
}Returns
struct OFSignUpResponse: OFSignUpResponseProtocol, OFCodableSendable {
public let token: String?
public let refreshToken: String?
public let player: OFAuthPlayerResponse?
public let action: String?
}Throws
{
method: method,
success: false,
error: error
}Log in a user
To authenticate an existing user:
Usage
func loginWIthEmailPassword() async {
do {
let result = try await OFSDK.shared.loginWith(params: OFAuthEmailPasswordParams(email: email, password: password))
print(result ?? "Empty response!")
} catch {
print("Failed to sign in: \(error.localizedDescription)")
return
}
}Parameters
struct OFAuthEmailPasswordParams: OFCodableSendable {
public let email: String
public let password: String
public let ecosystemGame: String?
}Returns
struct OFAuthorizationResponse: OFAuthorizationResponseProtocol, OFCodableSendable {
public let token: String?
public let refreshToken: String?
public let player: OFAuthPlayerResponse?
public let action: String?
}Throws
{
method: method,
success: false,
error: error
}