From 59620f60e84897333fc82669bebb6f74b2955f0d Mon Sep 17 00:00:00 2001 From: jimmylee Date: Sun, 23 Aug 2020 22:59:37 -0700 Subject: [PATCH] authentication: actually catch the error when the viewer model fails to initialize --- components/core/Application.js | 31 +++++++++---------------------- pages/api/hydrate.js | 12 ++++++------ 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/components/core/Application.js b/components/core/Application.js index fd5456c9..e9df5df4 100644 --- a/components/core/Application.js +++ b/components/core/Application.js @@ -120,11 +120,7 @@ export default class ApplicationPage extends React.Component { } // NOTE(jim): Only allow the sidebar to show with file drag and drop. - if ( - e.dataTransfer.items && - e.dataTransfer.items.length && - e.dataTransfer.items[0].kind !== "file" - ) { + if (e.dataTransfer.items && e.dataTransfer.items.length && e.dataTransfer.items[0].kind !== "file") { return; } @@ -212,12 +208,13 @@ export default class ApplicationPage extends React.Component { rehydrate = async (options) => { const response = await Actions.hydrateAuthenticatedUser(); - console.log("REHYDRATION CALL", response); - if (!response || response.error) { + alert("TODO: error fetching authenticated viewer"); return null; } + console.log("REHYDRATION CALL", response); + const updates = { viewer: State.getInitialState(response.data), selected: State.getSelectedState(response.data), @@ -277,8 +274,7 @@ export default class ApplicationPage extends React.Component { _handleDeleteYourself = async () => { // TODO(jim): // Put this somewhere better for messages. - const message = - "Do you really want to delete your account? It will be permanently removed"; + const message = "Do you really want to delete your account? It will be permanently removed"; if (!window.confirm(message)) { return false; } @@ -449,12 +445,8 @@ export default class ApplicationPage extends React.Component { - + url="https://slate.host/_"> + ); } @@ -527,17 +519,12 @@ export default class ApplicationPage extends React.Component { return ( - + + onDismissSidebar={this._handleDismissSidebar}> {scene} diff --git a/pages/api/hydrate.js b/pages/api/hydrate.js index 5daf70a1..bb0e95c9 100644 --- a/pages/api/hydrate.js +++ b/pages/api/hydrate.js @@ -11,14 +11,14 @@ export default async (req, res) => { const id = Utilities.getIdFromCookie(req); if (!id) { - return res - .status(500) - .json({ decorator: "SERVER_HYDRATE_FAILURE", error: true }); + return res.status(500).json({ decorator: "SERVER_HYDRATE_FAILURE", error: true }); } const data = await ViewerManager.getById({ id }); - return res - .status(200) - .send({ decorator: "SERVER_HYDRATE", success: true, data }); + if (!data) { + return res.status(500).json({ decorator: "SERVER_VIEWER_DATA_ERROR", error: true, data: null }); + } + + return res.status(200).send({ decorator: "SERVER_HYDRATE", success: true, data }); };