~vpzom/bracketmonster

0cdaa5c4ccf1dcd9e8fc227ca0217f642a555c91 — Colin Reeder 5 months ago ff99f5a
Maybe fix login loading
1 files changed, 18 insertions(+), 16 deletions(-)

M rosebush/src/client/App.tsx
M rosebush/src/client/App.tsx => rosebush/src/client/App.tsx +18 -16
@@ 67,23 67,25 @@ export default class App extends Component<Props, State> {
	}

	public componentDidMount() {
		const hasLogin = !!isomorphicCookie.load("rosebushToken");

		console.log("hasLogin: ", hasLogin);

		if(hasLogin && !(this.state.userInfo.state === "done" && this.state.userInfo.state !== null)) {
			fetch("/api/unstable/users/~me")
				.then(res => res.json())
				.then(info => {
					if(this.state.userInfo.state === "loading") {
						this.setUserInfo(info);
					}
				})
		if(this.state.userInfo.state !== "done") {
			const hasLogin = !!isomorphicCookie.load("rosebushToken");

			console.log("hasLogin: ", hasLogin);

			if(hasLogin) {
				fetch("/api/unstable/users/~me")
					.then(res => res.json())
					.then(info => {
							if(this.state.userInfo.state === "loading") {
							this.setUserInfo(info);
							}
							})
				.catch(err => {
					this.setState({userInfo: {state: "failed", error: err}});
				});
		} else {
			this.setState({userInfo: {state: "done", value: null}});
						this.setState({userInfo: {state: "failed", error: err}});
						});
			} else {
				this.setState({userInfo: {state: "done", value: null}});
			}
		}
	}