Skip to content

Commit

Permalink
Fix "infinite loading" screen for new logins. Remove unnecessary logg…
Browse files Browse the repository at this point in the history
…ing.
  • Loading branch information
BrunoBernardino committed Jan 4, 2022
1 parent 3684230 commit 31c2c9c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
6 changes: 0 additions & 6 deletions lib/data-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down
12 changes: 7 additions & 5 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,24 @@ 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',
text: 'Something went wrong getting user info.',
});
}

return {
currency: 'USD',
theme: 'light',
};
return defaultAuthToken;
};

export const isLoggedIn = async () => {
Expand Down
4 changes: 3 additions & 1 deletion modules/auth/LoginButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -28,6 +28,8 @@ const LoginButton = () => {
'success',
);

updatePreferences();

window.location.reload();
} else {
if (error) {
Expand Down

0 comments on commit 31c2c9c

Please sign in to comment.