Fix Android APK Issues Phase 2
This commit is contained in:
@@ -6,7 +6,10 @@ import { supabase } from '../../services/supabase';
|
||||
import { makeRedirectUri } from 'expo-auth-session';
|
||||
import * as QueryParams from 'expo-auth-session/build/QueryParams';
|
||||
import * as Linking from 'expo-linking';
|
||||
|
||||
import * as WebBrowser from 'expo-web-browser';
|
||||
import { handleAuthRedirectUrl } from '../../auth/authRedirect';
|
||||
import { addAuthDebugEvent, getAuthDebugEvents, clearAuthDebugEvents } from '../../debug/authDebug';
|
||||
import { clearSpotifyTokens } from '../../auth/spotifyToken';
|
||||
// @ts-ignore
|
||||
export default function LoginScreen({ navigation }) {
|
||||
const [email, setEmail] = useState('');
|
||||
@@ -33,14 +36,65 @@ export default function LoginScreen({ navigation }) {
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
const handleAuthDebug = async () => {
|
||||
const events = await getAuthDebugEvents();
|
||||
Alert.alert('Auth Debug Events', JSON.stringify(events, null, 2));
|
||||
};
|
||||
|
||||
const handleResetAuth = async () => {
|
||||
await supabase.auth.signOut();
|
||||
await clearSpotifyTokens();
|
||||
await clearAuthDebugEvents();
|
||||
Alert.alert('Reset', 'Auth state cleared.');
|
||||
};
|
||||
|
||||
const handleSpotifyLogin = async () => {
|
||||
const redirectUrl = Linking.createURL('/');
|
||||
const { data, error } = await supabase.auth.signInWithOAuth({
|
||||
provider: 'spotify',
|
||||
options: { redirectTo: redirectUrl }
|
||||
});
|
||||
if (data?.url) {
|
||||
await Linking.openURL(data.url);
|
||||
try {
|
||||
const redirectTo = "roadtripdj://auth/callback";
|
||||
await addAuthDebugEvent({ event: 'login_button_pressed', redirectTo });
|
||||
|
||||
const { data, error } = await supabase.auth.signInWithOAuth({
|
||||
provider: 'spotify',
|
||||
options: {
|
||||
redirectTo,
|
||||
skipBrowserRedirect: true,
|
||||
scopes: "user-read-email user-read-private playlist-modify-public playlist-modify-private",
|
||||
queryParams: {
|
||||
show_dialog: "true"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await addAuthDebugEvent({
|
||||
event: 'oauth_url_created',
|
||||
success: !!data?.url,
|
||||
host: data?.url ? data.url.split('?')[0] : null
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (data?.url) {
|
||||
const result = await WebBrowser.openAuthSessionAsync(data.url, redirectTo);
|
||||
await addAuthDebugEvent({ event: 'web_browser_closed', type: result.type });
|
||||
if (result.type === 'success' && result.url) {
|
||||
await addAuthDebugEvent({ event: 'web_browser_success_url_received', success: true });
|
||||
await addAuthDebugEvent({ event: 'processing_web_browser_success_url' });
|
||||
|
||||
await handleAuthRedirectUrl(result.url);
|
||||
|
||||
const { data: sessionData } = await supabase.auth.getSession();
|
||||
await addAuthDebugEvent({
|
||||
event: 'post_browser_getSession',
|
||||
user_exists: Boolean(sessionData.session?.user),
|
||||
provider_token_exists: Boolean((sessionData.session as any)?.provider_token)
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.error('🚀 [LoginScreen] OAuth Error:', e);
|
||||
Alert.alert('Erro de Autenticação', e.message);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -103,6 +157,14 @@ export default function LoginScreen({ navigation }) {
|
||||
<Text style={styles.spotifyButtonText}>Entrar com Spotify</Text>
|
||||
</TouchableOpacity>
|
||||
|
||||
<TouchableOpacity style={{ padding: 10, alignItems: 'center' }} onPress={handleAuthDebug}>
|
||||
<Text style={{ color: colors.textSecondary }}>Auth Debug</Text>
|
||||
</TouchableOpacity>
|
||||
|
||||
<TouchableOpacity style={{ padding: 10, alignItems: 'center', marginBottom: 10 }} onPress={handleResetAuth}>
|
||||
<Text style={{ color: 'red' }}>Reset Auth</Text>
|
||||
</TouchableOpacity>
|
||||
|
||||
<View style={styles.footerContainer}>
|
||||
<Text style={styles.footerText}>Não tens conta? </Text>
|
||||
<TouchableOpacity onPress={() => navigation.navigate('Register')}>
|
||||
|
||||
Reference in New Issue
Block a user