Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,18 @@ function AuthGate() {
const group = segmentList[0]
const screen = segmentList[1]
const inAuthGroup = group === '(auth)'
const inOAuthCallback = group === 'oauth'
const hasOnboardingToken =
typeof onboardingToken === 'string' && onboardingToken.trim().length > 0
const isLoginRoute = inAuthGroup && screen === 'login'
const isAgreementRoute = inAuthGroup && screen === 'agreement'
const isOnboardingRoute = inAuthGroup && screen === 'onboarding'
const isMidSignupRoute = isAgreementRoute || isOnboardingRoute

if (inOAuthCallback) {
return
}

if (isAuthenticated && inAuthGroup) {
router.replace('/(tabs)')
return
Expand All @@ -145,11 +150,11 @@ function AuthGate() {
}

if (isLoginRoute || !inAuthGroup) {
router.replace('/(auth)/agreement')
router.replace('/agreement')
return
}

router.replace('/(auth)/agreement')
router.replace('/agreement')
return
}

Expand Down Expand Up @@ -203,6 +208,7 @@ function RootLayoutNav() {
<Stack screenOptions={{ headerShown: false }}>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="(auth)" options={{ headerShown: false }} />
<Stack.Screen name="oauth/x" options={{ headerShown: false }} />
{/* Works detail screen โ€” header managed by Stack.Screen inside the screen */}
<Stack.Screen name="modal" options={{ presentation: 'modal', headerShown: false }} />
</Stack>
Expand Down
105 changes: 105 additions & 0 deletions app/oauth/x.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { useEffect, useRef } from 'react'
import { ActivityIndicator, Alert, StyleSheet, Text, View } from 'react-native'
import { useLocalSearchParams, useRouter } from 'expo-router'

import { useXLogin } from '../../src/features/auth/hooks'
import {
clearPendingXOAuthSession,
getPendingXOAuthSession,
X_OAUTH_CONFIG,
} from '../../src/features/auth/lib/xOAuth'
import { C, Typography } from '../../src/theme'

export default function XOAuthCallbackScreen() {
const params = useLocalSearchParams<{
code?: string
state?: string
error?: string
error_description?: string
}>()
const router = useRouter()
const xLoginMutation = useXLogin()
const handledRef = useRef(false)

useEffect(() => {
if (handledRef.current) return
handledRef.current = true

const completeLogin = async () => {
const code = Array.isArray(params.code) ? params.code[0] : params.code
const state = Array.isArray(params.state) ? params.state[0] : params.state
const oauthError = Array.isArray(params.error)
? params.error[0]
: params.error
const oauthErrorDescription = Array.isArray(params.error_description)
? params.error_description[0]
: params.error_description

console.log('[X OAuth Callback] params:', {
hasCode: !!code,
state,
error: oauthError,
errorDescription: oauthErrorDescription,
})

if (oauthError) {
await clearPendingXOAuthSession()
Alert.alert('๋กœ๊ทธ์ธ ์‹คํŒจ', 'X ๋กœ๊ทธ์ธ์ด ์ทจ์†Œ๋˜์—ˆ๊ฑฐ๋‚˜ ์‹คํŒจํ–ˆ์–ด์š”.')
router.replace('/(auth)/login')
return
}

if (!code || !state) {
await clearPendingXOAuthSession()
Alert.alert('๋กœ๊ทธ์ธ ์‹คํŒจ', 'X ๋กœ๊ทธ์ธ ์‘๋‹ต์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์•„์š”.')
router.replace('/(auth)/login')
return
}

const pendingSession = await getPendingXOAuthSession()

if (!pendingSession) {
Alert.alert('๋กœ๊ทธ์ธ ์‹คํŒจ', 'X ๋กœ๊ทธ์ธ ์„ธ์…˜์ด ๋งŒ๋ฃŒ๋˜์—ˆ์–ด์š”. ๋‹ค์‹œ ์‹œ๋„ํ•ด์ฃผ์„ธ์š”.')
router.replace('/(auth)/login')
return
}

if (pendingSession.state !== state) {
await clearPendingXOAuthSession()
Alert.alert('๋กœ๊ทธ์ธ ์‹คํŒจ', 'X ๋กœ๊ทธ์ธ ๊ฒ€์ฆ์— ์‹คํŒจํ–ˆ์–ด์š”. ๋‹ค์‹œ ์‹œ๋„ํ•ด์ฃผ์„ธ์š”.')
router.replace('/(auth)/login')
return
}

await clearPendingXOAuthSession()
xLoginMutation.mutate({
code,
redirectUri: X_OAUTH_CONFIG.redirectUri,
codeVerifier: pendingSession.codeVerifier,
})
}

void completeLogin()
}, [params, router, xLoginMutation])

return (
<View style={styles.screen}>
<ActivityIndicator size="small" color={C.primary} />
<Text style={styles.text}>X ๋กœ๊ทธ์ธ ์ฒ˜๋ฆฌ ์ค‘์ž…๋‹ˆ๋‹ค.</Text>
</View>
)
}

const styles = StyleSheet.create({
screen: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
gap: 12,
backgroundColor: C.card,
},
text: {
...Typography.body2Medium,
color: C.text,
},
})
20 changes: 20 additions & 0 deletions assets/common/cardshare/image-gallery-saved.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 18 additions & 2 deletions assets/icons/common/comment-dropdown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/common/icon-download.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/common/icon-help.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading