Skip to content

How to integrate expirable into CelyUser to manage different tokens? #27

@rlam3

Description

@rlam3

@initFabian I'd like to get your opinion on how to add the following Expirable protocol so I can manage tokens.

https://github.com/AndrewSB/Expirable

This will enable us see which token expired or is expiring soon. So far following your example I don't know where I am able to enable the Expirable protocol

struct AuthUser: CelyUser {
    
    enum Property: CelyProperty {
        
        case username = "username"
        case email = "email"
        case access_token = "access_token"
        case refresh_token = "refresh_token"
            
        func securely() -> Bool {
            switch self {
            case .access_token, .refresh_token:
                return true
            default:
                return false
            }
        }
        
        func persisted() -> Bool {
            switch self {
            case .access_token, .refresh_token:
                return true
            default:
                return false
            }
        }
        
        func save(_ value: Any) {
            Cely.save(value, forKey: rawValue, securely: securely(), persisted: persisted())
        }
        
        func get() -> Any? {
            return Cely.get(key: rawValue)
        }
    }
}

// MARK: - Save/Get User Properties

extension AuthUser {
    
    static func save(_ value: Any, as property: Property) {
        property.save(value)
    }
    
    static func save(_ data: [Property : Any]) {
        data.forEach { property, value in
            property.save(value)
        }
    }
    
    static func get(_ property: Property) -> Any? {
        return property.get()
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions