fix: 登录页面
This commit is contained in:
parent
a2ba14d312
commit
1a6df3c806
|
|
@ -1,24 +1,23 @@
|
|||
import { useState, useRef, useEffect } from 'react'
|
||||
import { Image } from 'expo-image'
|
||||
import { LinearGradient } from 'expo-linear-gradient'
|
||||
import { useRouter } from 'expo-router'
|
||||
import { StatusBar } from 'expo-status-bar'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import {
|
||||
View,
|
||||
Text,
|
||||
StyleSheet,
|
||||
Animated,
|
||||
Dimensions,
|
||||
ScrollView,
|
||||
Platform,
|
||||
Pressable,
|
||||
StatusBar as RNStatusBar,
|
||||
Animated,
|
||||
Platform,
|
||||
ScrollView,
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
} from 'react-native'
|
||||
import { StatusBar } from 'expo-status-bar'
|
||||
import { LinearGradient } from 'expo-linear-gradient'
|
||||
import { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context'
|
||||
import { Image } from 'expo-image'
|
||||
import { useRouter } from 'expo-router'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { PointsIcon, SearchIcon, DownArrowIcon, WhiteStarIcon } from '@/components/icon'
|
||||
import { AuthForm } from '@/components/blocks/AuthForm'
|
||||
import { DownArrowIcon, PointsIcon, SearchIcon, WhiteStarIcon } from '@/components/icon'
|
||||
import { useActivates } from '@/hooks/use-activates'
|
||||
|
||||
const { width: screenWidth } = Dimensions.get('window')
|
||||
|
|
@ -279,10 +278,6 @@ export default function HomeScreen() {
|
|||
{renderTabs()}
|
||||
</View>
|
||||
|
||||
<View className='py-6'>
|
||||
<AuthForm mode='register' />
|
||||
</View>
|
||||
|
||||
{/* 内容网格 */}
|
||||
<View
|
||||
style={styles.gridContainer}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ export default function RootLayout() {
|
|||
return (
|
||||
<Providers>
|
||||
<Stack>
|
||||
<Stack.Screen name="auth" options={{ headerShown: false }} />
|
||||
<Stack.Screen name="modal" options={{ presentation: 'modal', title: 'Modal' }} />
|
||||
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
||||
<Stack.Screen name="channels" options={{ headerShown: false }} />
|
||||
|
|
|
|||
76
app/auth.tsx
76
app/auth.tsx
|
|
@ -1,5 +1,75 @@
|
|||
import React, { useEffect } from 'react'
|
||||
import { View, StyleSheet, StatusBar as RNStatusBar } from 'react-native'
|
||||
import { StatusBar } from 'expo-status-bar'
|
||||
import { SafeAreaView } from 'react-native-safe-area-context'
|
||||
import { useRouter } from 'expo-router'
|
||||
import { LinearGradient } from 'expo-linear-gradient'
|
||||
import { AuthForm } from '@/components/blocks/AuthForm'
|
||||
import { useSession } from '@/lib/auth'
|
||||
|
||||
export default function Auth() {
|
||||
const router = useRouter()
|
||||
const { data: session, isPending } = useSession()
|
||||
|
||||
export default () => {
|
||||
return null;
|
||||
}
|
||||
useEffect(() => {
|
||||
// 如果用户已登录,跳转到首页
|
||||
if (session?.user) {
|
||||
router.replace('/(tabs)' as any)
|
||||
}
|
||||
}, [session, router])
|
||||
|
||||
// 会话加载中显示空白
|
||||
if (isPending) {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<StatusBar style="light" />
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
// 如果已登录,不显示内容(等待跳转)
|
||||
if (session?.user) {
|
||||
return null
|
||||
}
|
||||
|
||||
const handleSuccess = () => {
|
||||
router.replace('/(tabs)' as any)
|
||||
}
|
||||
|
||||
return (
|
||||
<LinearGradient
|
||||
colors={['#1a1a2e', '#16213e', '#0f3460']}
|
||||
locations={[0, 0.5, 1]}
|
||||
start={{ x: 0, y: 0 }}
|
||||
end={{ x: 1, y: 1 }}
|
||||
style={styles.background}
|
||||
>
|
||||
<SafeAreaView style={styles.container} edges={['top']}>
|
||||
<StatusBar style="light" />
|
||||
<RNStatusBar barStyle="light-content" />
|
||||
|
||||
<View style={styles.content}>
|
||||
<AuthForm onSuccess={handleSuccess} />
|
||||
</View>
|
||||
</SafeAreaView>
|
||||
</LinearGradient>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
background: {
|
||||
flex: 1,
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
},
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: 'transparent',
|
||||
},
|
||||
content: {
|
||||
flex: 1,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
paddingHorizontal: 20,
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -83,6 +83,9 @@ export const authClient = createAuthClient({
|
|||
storage,
|
||||
scheme: 'duooomi',
|
||||
fetchOptions: {
|
||||
headers: {
|
||||
"x-ownerid": ""
|
||||
},
|
||||
auth: {
|
||||
type: 'Bearer',
|
||||
token: async () => {
|
||||
|
|
|
|||
|
|
@ -1,15 +1 @@
|
|||
import * as SecureStore from "expo-secure-store";
|
||||
|
||||
export const storage = {
|
||||
async getItem(key: string): Promise<string | null> {
|
||||
return await SecureStore.getItemAsync(key);
|
||||
},
|
||||
|
||||
async setItem(key: string, value: string): Promise<void> {
|
||||
await SecureStore.setItemAsync(key, value);
|
||||
},
|
||||
|
||||
async removeItem(key: string): Promise<void> {
|
||||
await SecureStore.deleteItemAsync(key);
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
/c/Users/imeep/Desktop/shopify/expo-popcore-app
|
||||
Loading…
Reference in New Issue