Hi @dan.woda,
I’m using the Auth0.swift framework.
Signup
let auth0Authentication = Auth0.authentication()
auth0Authentication
.createUser(email: email,
username: nil,
password: password,
connection: "Username-Password-Authentication",
userMetadata: nil)
.start { [weak self] result in
switch result {
case .success(let databaseUser):
self?.login(userInfo: userInfo) { (user, error) in
completion(user, error)
}
case .failure(let error):
self?.handleLoginError(error: error, completion: completion)
}
}
Login
auth0Authentication
.login(usernameOrEmail: email,
password: password,
realm: "Username-Password-Authentication",
audience: audience,
scope: "openid profile email offline_access",
parameters: nil)
.start { [weak self] result in
switch result {
case .success(let credentials):
self?.credentials = credentials
completion(user, nil)
case .failure(let error):
self?.handleLoginError(error: error, completion: completion)
}
}
Silent login
let credentialsManager = CredentialsManager(authentication: auth0Authentication)
if credentialsManager.hasValid() {
credentialsManager.credentials { [weak self] (error, credentials) in
self?.credentials = credentials
if let error = error {
self?.handleLoginError(error: error, completion: completion)
} else {
completion(user, nil)
}
}
} else {
completion(nil, Errors.invalidCredentials)
}
The handleLoginError
function is mostly used to either display any error found or to continue through the MFA flow, which we also have enabled.
Thanks,
Guy