AuthenticationState

@frozen
public enum AuthenticationState : Codable, Equatable, CustomStringConvertible, CustomDebugStringConvertible

A value representing an authentication state.

After using the AuthenticationService.unauthenticate(queue:then:) method, the authentication always goes into the AuthenticationState.unauthenticated state.

After a successful authentication, the authentication always goes into the AuthenticationState.authenticated(details:) state.

After a failed authentication, the authentication state never changes. In particular, the AuthenticationState.authenticated(details:) state is preserved since the previous authentication is always valid.

When the connection to the back-end is lost, the authentication state is frozen, unless the AuthenticationService.unauthenticate(queue:then:) method is used.

Cases

  • Indicates that there is a valid authentication token.

    The associated value contains information about the authenticated user.

    From this state:

    • the AuthenticationService.unauthenticate(queue:then:) method brings to the .unauthenticated state,
    • the expiration of the token or a reject of the token by the back-end when going back online brings to the .invalid state.

    Declaration

    Swift

    case authenticated(details: AuthenticationDetails)
  • Indicates that the current authentication token is no longer valid.

    This state is obtained in two cases:

    1. when the authentication token has expired,
    2. when the authentication token is rejected by the back-end when going back online.

    From this state:

    Declaration

    Swift

    case invalid
  • Indicates that there is currently no authentication token.

    From this state, a successful authentication brings to the .authenticated(details:) state.

    Declaration

    Swift

    case unauthenticated

Initializers

  • Declaration

    Swift

    public init(from decoder: Decoder) throws

Encodable Protocol

  • Declaration

    Swift

    public func encode(to encoder: Encoder) throws

API

  • The details of the user currently authenticated.

    This property is nil when there is currently no valid authentication token. i.e. when this value does not match the .authenticated(details:) case.

    Declaration

    Swift

    public var details: AuthenticationDetails? { get }

CustomStringConvertible Protocol

  • Declaration

    Swift

    public var description: String { get }

CustomDebugStringConvertible Protocol

  • Declaration

    Swift

    public var debugDescription: String { get }