Skip to content

Commit

Permalink
fix: Allow creation of new accounts + guests
Browse files Browse the repository at this point in the history
Restore the default behavior which is to automatically
create a new user if the provided UID to getUserData
is not a valid user.

This behavior is IMO not ideal; maybe change it later
  • Loading branch information
mizlan committed Apr 17, 2024
1 parent 4e2cccd commit 7790db1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/containers/AppContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ const mapStateToProps = (state) => ({

const mapDispatchToProps = (dispatch) => ({
loadUserData: async (uid, onFailure) => {
const { ok, data /* error */ } = await fetch.getUserData(uid, true);
const { ok, data, error } = await fetch.getUserData(uid, true);
// if the request went fine, and there's a non empty userData
if (ok && data && data.userData && Object.keys(data.userData).length) {
if (data.programs) {
dispatch(loadPrograms(data.programs));
}
dispatch(loadUserData(uid, data.userData));
} else {
console.error('Error getting user data:', error);
onFailure('SERVER ERROR: Unable to get user data from server');
}
},
Expand Down
5 changes: 5 additions & 0 deletions src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export const getUserData = async (
const ok = status === 200;
const data = ok ? await result.json() : {};
const error = !ok ? await result.text() : '';
if (!ok) {
console.error(error);
await createUser(uid);
return getUserData(uid, includePrograms);
}
return { ok, data, error };
} catch (err) {
if (err instanceof Error) return { ok: false, data: {}, error: err.message };
Expand Down

0 comments on commit 7790db1

Please sign in to comment.