Update Spotify Auth implementation

This commit is contained in:
Eduardo Silva
2026-05-15 12:37:02 +01:00
parent 56c2f20c11
commit ad64bb2572
2 changed files with 26 additions and 22 deletions

View File

@@ -32,22 +32,24 @@ export default function LoginScreen({ navigation }) {
};
const handleSpotifyAuth = async () => {
Alert.alert('Teste', 'O botão do Spotify foi clicado!');
try {
const redirectUri = makeRedirectUri();
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'spotify',
options: {
redirectTo: makeRedirectUri()
}
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.');

View File

@@ -43,22 +43,24 @@ export default function RegisterScreen({ navigation }) {
};
const handleSpotifyAuth = async () => {
Alert.alert('Teste', 'O botão do Spotify foi clicado!');
try {
const redirectUri = makeRedirectUri();
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'spotify',
options: {
redirectTo: makeRedirectUri()
}
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.');