From 3dd0d598710c949aa26081bbc009078953c7e48d Mon Sep 17 00:00:00 2001 From: "Ng Wing Tat, David" Date: Wed, 15 Jan 2020 14:40:44 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20Add=20redirect=20fallback=20case?= =?UTF-8?q?=20liker.land=20OAuth=20screen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../likerland-oauth-screen.tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/screens/likerland-oauth-screen/likerland-oauth-screen.tsx b/app/screens/likerland-oauth-screen/likerland-oauth-screen.tsx index 728944db7..b97f5ea86 100644 --- a/app/screens/likerland-oauth-screen/likerland-oauth-screen.tsx +++ b/app/screens/likerland-oauth-screen/likerland-oauth-screen.tsx @@ -1,7 +1,6 @@ import * as React from "react" import { Alert, - Platform, View, } from "react-native" import { NavigationScreenProps } from "react-navigation" @@ -32,6 +31,12 @@ export interface LikerLandOAuthScreenProps extends NavigationScreenProps<{}> { @inject("rootStore") export class LikerLandOAuthScreen extends React.Component { + redirectTimer?: NodeJS.Timeout + + state = { + hasHandledRedirect: false, + } + private handleError = async () => { await this.props.rootStore.userStore.logout() this.props.rootStore.userStore.setIsSigningIn(false) @@ -39,6 +44,12 @@ export class LikerLandOAuthScreen extends React.Component { + if (this.state.hasHandledRedirect) return + this.setState({ hasHandledRedirect: true }) + if (this.redirectTimer) { + clearTimeout(this.redirectTimer) + this.redirectTimer = undefined + } await Promise.all([ this.props.rootStore.userStore.fetchUserInfo(), this.props.rootStore.userStore.fetchLikerLandUserInfo(), @@ -52,8 +63,9 @@ export class LikerLandOAuthScreen extends React.Component { if (url.includes("/following")) { this.handlePostSignIn() - } else if (Platform.OS === "android" && url.includes("/oauth/redirect")) { - setTimeout(this.handlePostSignIn, 2000) + } else if (url.includes("/oauth/redirect")) { + // Fallback to use timer if the above case not working + this.redirectTimer = setTimeout(this.handlePostSignIn, 2000) } else if (url.includes("/in/register")) { this.handleError() logError("Error when signing in to liker.land, like.co shows register page")