Add files via upload
This commit is contained in:
parent
f36d85bdb0
commit
5be2cbda15
6 changed files with 237 additions and 372 deletions
|
|
@ -1,57 +1,24 @@
|
|||
/**
|
||||
* app/auth/callback.tsx
|
||||
* Handles OAuth deep link: burmalda://auth/callback?code=...
|
||||
* expo-web-browser closes the session, then this page completes the flow.
|
||||
*/
|
||||
import { useEffect, useState } from 'react';
|
||||
import { View, Text, StyleSheet, ActivityIndicator } from 'react-native';
|
||||
import { useLocalSearchParams, router } from 'expo-router';
|
||||
import { useEffect } from 'react';
|
||||
import { View, ActivityIndicator } from 'react-native';
|
||||
import * as WebBrowser from 'expo-web-browser';
|
||||
import { Colors, Font } from '../../constants/theme';
|
||||
import { exchangeCode, saveTokens } from '../../services/api';
|
||||
import { useAuth } from '../../store';
|
||||
import { saveUser } from '../../hooks/useAuth';
|
||||
import { router } from 'expo-router';
|
||||
|
||||
// Complete the auth session so expo-web-browser can close
|
||||
// Complete the browser auth session so WebBrowser.openAuthSessionAsync returns
|
||||
WebBrowser.maybeCompleteAuthSession();
|
||||
|
||||
export default function AuthCallback() {
|
||||
const params = useLocalSearchParams<{ code?: string; error?: string }>();
|
||||
const { setUser } = useAuth();
|
||||
const [status, setStatus] = useState('Завершаем вход…');
|
||||
|
||||
useEffect(() => {
|
||||
async function finish() {
|
||||
const code = params.code;
|
||||
if (!code) {
|
||||
const msg = params.error || 'Код авторизации отсутствует';
|
||||
setStatus(`Ошибка: ${msg}`);
|
||||
setTimeout(() => router.replace('/auth'), 2000);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const data = await exchangeCode(code);
|
||||
await saveTokens(data.access_token, data.refresh_token);
|
||||
await saveUser(data.user);
|
||||
setUser(data.user);
|
||||
router.replace('/(tabs)');
|
||||
} catch (e: any) {
|
||||
setStatus(`Ошибка: ${e.message || 'Не удалось войти'}`);
|
||||
setTimeout(() => router.replace('/auth'), 2500);
|
||||
}
|
||||
}
|
||||
finish();
|
||||
// The actual code exchange is handled in auth.tsx via openAuthSessionAsync
|
||||
// This page only shows briefly if opened directly; redirect to auth
|
||||
const t = setTimeout(() => {
|
||||
router.replace('/auth');
|
||||
}, 500);
|
||||
return () => clearTimeout(t);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<View style={s.root}>
|
||||
<ActivityIndicator size="large" color={Colors.accent} />
|
||||
<Text style={s.text}>{status}</Text>
|
||||
<View style={{ flex: 1, backgroundColor: '#07071a', alignItems: 'center', justifyContent: 'center' }}>
|
||||
<ActivityIndicator color="#4361ee" size="large" />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const s = StyleSheet.create({
|
||||
root: { flex: 1, backgroundColor: Colors.bg, alignItems: 'center', justifyContent: 'center', gap: 20 },
|
||||
text: { color: Colors.text, fontSize: Font.md, textAlign: 'center', opacity: 0.7 },
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue