diff --git a/lib/data-utils.ts b/lib/data-utils.ts index ece58cf..2b248e6 100644 --- a/lib/data-utils.ts +++ b/lib/data-utils.ts @@ -86,9 +86,6 @@ const loadItemsAsync = async () => { await userbase.openDatabase({ databaseName: 'budgets', changeHandler: async (items) => { - // TODO: Remove this - console.log('======== data-utils.loadItemsAsync.budgets'); - console.log(items.length); const budgets = items .map(getBudgetFromItem) .filter((budget) => Boolean(budget)); @@ -102,9 +99,6 @@ const loadItemsAsync = async () => { await userbase.openDatabase({ databaseName: 'expenses', changeHandler: (items) => { - // TODO: Remove this - console.log('======== data-utils.loadItemsAsync.expenses'); - console.log(items.length); const expenses = items .map(getExpenseFromItem) .filter((expense) => Boolean(expense)); diff --git a/lib/utils.ts b/lib/utils.ts index e90dae2..34db4bb 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -155,11 +155,16 @@ export const doLogout = async () => { type GetUserInfo = () => AuthToken; export const getUserInfo: GetUserInfo = () => { + const defaultAuthToken: AuthToken = { + currency: 'USD', + theme: 'light', + }; + try { const userInfo: AuthToken = JSON.parse( localStorage.getItem(`${sessionNamespace}:userInfo`), ); - return userInfo; + return userInfo || defaultAuthToken; } catch (error) { Swal.fire({ title: 'Uh-oh', @@ -167,10 +172,7 @@ export const getUserInfo: GetUserInfo = () => { }); } - return { - currency: 'USD', - theme: 'light', - }; + return defaultAuthToken; }; export const isLoggedIn = async () => { diff --git a/modules/auth/LoginButton.tsx b/modules/auth/LoginButton.tsx index f38a604..81b7ee8 100644 --- a/modules/auth/LoginButton.tsx +++ b/modules/auth/LoginButton.tsx @@ -6,7 +6,7 @@ import Button from 'components/Button'; import TextInput from 'components/TextInput'; import Paragraph from 'components/Paragraph'; import { validateLogin, createAccount } from 'lib/data-utils'; -import { showNotification } from 'lib/utils'; +import { showNotification, updatePreferences } from 'lib/utils'; const LoginButton = () => { const [isSubmitting, setIsSubmitting] = useState(false); @@ -28,6 +28,8 @@ const LoginButton = () => { 'success', ); + updatePreferences(); + window.location.reload(); } else { if (error) {