Skip to content

Commit

Permalink
🥅 Add redirect fallback case liker.land OAuth screen
Browse files Browse the repository at this point in the history
  • Loading branch information
nwingt committed Jan 15, 2020
1 parent f591e89 commit 3dd0d59
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions app/screens/likerland-oauth-screen/likerland-oauth-screen.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from "react"
import {
Alert,
Platform,
View,
} from "react-native"
import { NavigationScreenProps } from "react-navigation"
Expand Down Expand Up @@ -32,13 +31,25 @@ export interface LikerLandOAuthScreenProps extends NavigationScreenProps<{}> {

@inject("rootStore")
export class LikerLandOAuthScreen extends React.Component<LikerLandOAuthScreenProps> {
redirectTimer?: NodeJS.Timeout

state = {
hasHandledRedirect: false,
}

private handleError = async () => {
await this.props.rootStore.userStore.logout()
this.props.rootStore.userStore.setIsSigningIn(false)
this.props.navigation.goBack()
}

private handlePostSignIn = async () => {
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(),
Expand All @@ -52,8 +63,9 @@ export class LikerLandOAuthScreen extends React.Component<LikerLandOAuthScreenPr
private handleURLChange = (url: string) => {
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")
Expand Down

0 comments on commit 3dd0d59

Please sign in to comment.