From ad64bb25729c29084a7c7e7aff0b47b727582f98 Mon Sep 17 00:00:00 2001 From: Eduardo Silva <240424@Mac.epvc2.local> Date: Fri, 15 May 2026 12:37:02 +0100 Subject: [PATCH] Update Spotify Auth implementation --- src/screens/auth/LoginScreen.tsx | 24 +++++++++++++----------- src/screens/auth/RegisterScreen.tsx | 24 +++++++++++++----------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/screens/auth/LoginScreen.tsx b/src/screens/auth/LoginScreen.tsx index 9149ba2..d802e43 100644 --- a/src/screens/auth/LoginScreen.tsx +++ b/src/screens/auth/LoginScreen.tsx @@ -32,22 +32,24 @@ export default function LoginScreen({ navigation }) { }; const handleSpotifyAuth = async () => { - Alert.alert('Teste', 'O botão do Spotify foi clicado!'); try { - const { data, error } = await supabase.auth.signInWithOAuth({ - provider: 'spotify', - options: { - redirectTo: makeRedirectUri() - } + const redirectUri = makeRedirectUri(); + const { data, error } = await supabase.auth.signInWithOAuth({ + provider: 'spotify', + options: { + redirectTo: redirectUri, + }, }); - if (error) { - Alert.alert('Erro no login Spotify', error.message); - return; - } + if (error) throw error; if (data?.url) { - await WebBrowser.openAuthSessionAsync(data.url, makeRedirectUri()); + const res = await WebBrowser.openAuthSessionAsync(data.url, redirectUri); + if (res.type === 'success') { + const { url } = res; + // Ensure Supabase catches the session from the returned URL + await supabase.auth.getSessionFromUrl(url); + } } } catch (err: any) { Alert.alert('Erro', err?.message || 'Ocorreu um erro no Spotify Auth.'); diff --git a/src/screens/auth/RegisterScreen.tsx b/src/screens/auth/RegisterScreen.tsx index 7bf8cfe..0481893 100644 --- a/src/screens/auth/RegisterScreen.tsx +++ b/src/screens/auth/RegisterScreen.tsx @@ -43,22 +43,24 @@ export default function RegisterScreen({ navigation }) { }; const handleSpotifyAuth = async () => { - Alert.alert('Teste', 'O botão do Spotify foi clicado!'); try { - const { data, error } = await supabase.auth.signInWithOAuth({ - provider: 'spotify', - options: { - redirectTo: makeRedirectUri() - } + const redirectUri = makeRedirectUri(); + const { data, error } = await supabase.auth.signInWithOAuth({ + provider: 'spotify', + options: { + redirectTo: redirectUri, + }, }); - if (error) { - Alert.alert('Erro no login Spotify', error.message); - return; - } + if (error) throw error; if (data?.url) { - await WebBrowser.openAuthSessionAsync(data.url, makeRedirectUri()); + const res = await WebBrowser.openAuthSessionAsync(data.url, redirectUri); + if (res.type === 'success') { + const { url } = res; + // Ensure Supabase catches the session from the returned URL + await supabase.auth.getSessionFromUrl(url); + } } } catch (err: any) { Alert.alert('Erro', err?.message || 'Ocorreu um erro no Spotify Auth.');