-
Notifications
You must be signed in to change notification settings - Fork 5.9k
feat: Persist user preferences in database #3746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
@ceviixx is attempting to deploy a commit to the umami-software Team on Vercel. A member of the Team first needs to authorize it. |
Greptile OverviewGreptile SummaryThis PR implements persistent user preferences by migrating them from localStorage-only storage to database-backed persistence. The changes add four new nullable columns ( The implementation introduces a new The solution maintains backward compatibility through nullable database columns and graceful fallbacks, allowing existing users to continue using the application while new preference updates get persisted to the database. Important Files Changed
Confidence score: 4/5
Sequence DiagramsequenceDiagram
participant User
participant LoginForm as "Login Form"
participant AuthAPI as "Auth API"
participant UserDB as "User Database"
participant ClientStorage as "Client Storage"
participant AppStore as "App Store"
User->>LoginForm: "Enter credentials and submit"
LoginForm->>AuthAPI: "POST /auth/login with username/password"
AuthAPI->>UserDB: "getUserByUsername() and checkPassword()"
UserDB-->>AuthAPI: "User data with preferences"
AuthAPI->>UserDB: "getUserPreferences(userId)"
UserDB-->>AuthAPI: "User preferences (theme, language, timezone, dateRange)"
AuthAPI-->>LoginForm: "Return token and user data with preferences"
LoginForm->>ClientStorage: "setClientAuthToken(token)"
LoginForm->>ClientStorage: "setClientPreferences(preferences)"
LoginForm->>AppStore: "setTheme(preferences.theme)"
LoginForm->>AppStore: "setUser(user)"
LoginForm->>User: "Redirect to /websites"
Note over User,AppStore: User changes preferences in settings
User->>LanguageSetting: "Select new language"
LanguageSetting->>ClientStorage: "saveLocale(language)"
LanguageSetting->>AuthAPI: "POST /users/{userId}/preferences with language"
AuthAPI->>UserDB: "updateUserPreferences(userId, {language})"
UserDB-->>AuthAPI: "Updated preferences"
User->>ThemeSetting: "Select new theme"
ThemeSetting->>AppStore: "setTheme(theme)"
ThemeSetting->>AuthAPI: "POST /users/{userId}/preferences with theme"
AuthAPI->>UserDB: "updateUserPreferences(userId, {theme})"
UserDB-->>AuthAPI: "Updated preferences"
User->>TimezoneSetting: "Select new timezone"
TimezoneSetting->>ClientStorage: "saveTimezone(timezone)"
TimezoneSetting->>AuthAPI: "POST /users/{userId}/preferences with timezone"
AuthAPI->>UserDB: "updateUserPreferences(userId, {timezone})"
UserDB-->>AuthAPI: "Updated preferences"
User->>DateRangeSetting: "Select new date range"
DateRangeSetting->>ClientStorage: "setItem(DATE_RANGE_CONFIG, dateRange)"
DateRangeSetting->>AuthAPI: "POST /users/{userId}/preferences with dateRange"
AuthAPI->>UserDB: "updateUserPreferences(userId, {dateRange})"
UserDB-->>AuthAPI: "Updated preferences"
Note over User,AppStore: User logs out
User->>LogoutPage: "Navigate to /logout"
LogoutPage->>ClientStorage: "removeClientAuthToken()"
LogoutPage->>ClientStorage: "removeClientPreferences()"
LogoutPage->>AppStore: "setUser(null)"
LogoutPage->>AuthAPI: "POST /auth/logout"
LogoutPage->>User: "Redirect to /login"
Note over User,AppStore: User logs in on different device
User->>LoginForm: "Enter credentials and submit"
LoginForm->>AuthAPI: "POST /auth/login with username/password"
AuthAPI->>UserDB: "getUserByUsername() and getUserPreferences()"
UserDB-->>AuthAPI: "User data with saved preferences from database"
AuthAPI-->>LoginForm: "Return token and user data with preferences"
LoginForm->>ClientStorage: "setClientPreferences(preferences) - sync from database"
LoginForm->>AppStore: "setTheme(preferences.theme) - restore user's theme"
LoginForm->>User: "User sees consistent settings across devices"
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
17 files reviewed, 4 comments
- Use DEFAULT_THEME constant for theme reset - Type user selector properly - Include LOCALE_CONFIG in preferences cleanup - Add newline to migration file
|
@mikecao @franciscao633 is it possible to merge or should I create an new PR to dev? |
Changes
Benefits
Migration
15_add_user_preferencesadds columns to user table