#pragma once // Spec: shell.md section 5 (UserSessionStore). DIFF: Keychain (whenUnlockedThisDeviceOnly) -> session.json in the // SDL pref path, mode 0600, atomic write, max 16 KiB; the secret is plaintext on disk, protected by file mode only. // Setting nullopt removes the key. The password is kept so the token can be silently re-obtained. #include #include #include "core/Observable.hpp" namespace dp { class SessionStore : public Observable { public: static SessionStore& instance(); // pref path explicit SessionStore(std::string directory); std::optional email() const { return email_; } std::optional password() const { return password_; } // false (and a log line "Error: failed to store in session file") when persisting failed. bool setEmail(const std::optional& value); bool setPassword(const std::optional& value); // Switches the backing directory (tests, profiles) and reloads from it. Empty = memory only. void rebind(std::string directory); void reload(); const std::string& filePath() const { return path_; } private: bool set(std::optional& slot, const std::optional& value, const char* key); bool save(); std::string path_; std::optional email_; std::optional password_; }; } // namespace dp