start refacto home and fix description
This commit is contained in:
+52
-54
@@ -1,34 +1,32 @@
|
||||
/* eslint-disable react/display-name */
|
||||
import { GoogleSigninButton } from "@react-native-google-signin/google-signin";
|
||||
import * as AuthSession from "expo-auth-session";
|
||||
import * as GoogleAuth from "expo-auth-session/providers/google";
|
||||
import * as WebBrowser from "expo-web-browser";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Pressable, Text, View } from "react-native";
|
||||
import { useGlobal } from "reactn";
|
||||
import { background } from "../assets";
|
||||
import GradientButton from "../components/GradientButton.js";
|
||||
import { Input } from "../components/Input.js";
|
||||
import ItemContainer from "../components/ItemContainer/ItemContainer.js";
|
||||
import firebase, { usersRef } from "../config/firebase";
|
||||
|
||||
import { GoogleSigninButton } from '@react-native-google-signin/google-signin';
|
||||
import * as AuthSession from 'expo-auth-session';
|
||||
import * as GoogleAuth from 'expo-auth-session/providers/google';
|
||||
import * as WebBrowser from 'expo-web-browser';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Pressable, Text, View } from 'react-native';
|
||||
import { useGlobal } from 'reactn';
|
||||
import { background } from '../assets';
|
||||
import GradientButton from '../components/GradientButton.js';
|
||||
import { Input } from '../components/Input.js';
|
||||
import ItemContainer from '../components/ItemContainer/ItemContainer.js';
|
||||
import firebase, { usersRef } from '../config/firebase';
|
||||
import {
|
||||
GOOGLE_ANDROID_CLIENT_ID,
|
||||
GOOGLE_IOS_CLIENT_ID,
|
||||
GOOGLE_WEB_CLIENT_ID,
|
||||
} from "../data/keys";
|
||||
import { isWeb } from "../hooks/useLayoutType";
|
||||
import Page from "../layouts/Page.js";
|
||||
import { Routes } from "../navigation";
|
||||
import { navigate } from "../navigation/NavigationService.js";
|
||||
import { FONT_FAMILY } from "../styles/Fonts.js";
|
||||
import Palette from "../styles/Palette.js";
|
||||
} from '../data/keys';
|
||||
import { isWeb } from '../hooks/useLayoutType';
|
||||
import Page from '../layouts/Page.js';
|
||||
import { Routes } from '../navigation';
|
||||
import { navigate } from '../navigation/NavigationService.js';
|
||||
import { FONT_FAMILY } from '../styles/Fonts.js';
|
||||
import Palette from '../styles/Palette.js';
|
||||
|
||||
export default ({ navigation }) => {
|
||||
WebBrowser.maybeCompleteAuthSession();
|
||||
const [, setTooltip] = useGlobal("_tooltip");
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [, setTooltip] = useGlobal('_tooltip');
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
// Let the provider compute a compliant redirect URI for native (com.googleusercontent.apps.<client-id>:/oauth2redirect)
|
||||
// Avoid forcing a custom scheme like musicland:// which Google can reject for native apps.
|
||||
@@ -41,12 +39,12 @@ export default ({ navigation }) => {
|
||||
// Use Authorization Code + PKCE to comply with Google OAuth for native apps
|
||||
responseType: AuthSession.ResponseType.Code,
|
||||
usePKCE: true,
|
||||
scopes: ["openid", "profile", "email"],
|
||||
scopes: ['openid', 'profile', 'email'],
|
||||
});
|
||||
|
||||
const afterLoginNavigate = async () => {
|
||||
const uid = firebase.auth().currentUser?.uid;
|
||||
if (!uid) throw new Error("Aucun utilisateur après connexion");
|
||||
if (!uid) throw new Error('Aucun utilisateur après connexion');
|
||||
const snap = await usersRef.doc(uid).get();
|
||||
const hasUserName = !!snap.data()?.userName;
|
||||
if (hasUserName) {
|
||||
@@ -62,8 +60,8 @@ export default ({ navigation }) => {
|
||||
await firebase.auth().signInWithEmailAndPassword(email.trim(), password);
|
||||
await afterLoginNavigate();
|
||||
} catch (e) {
|
||||
console.log("Login error", e?.message);
|
||||
setTooltip({ text: e?.message || "Connexion impossible", type: "error" });
|
||||
console.log('Login error', e?.message);
|
||||
setTooltip({ text: e?.message || 'Connexion impossible', type: 'error' });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -74,24 +72,24 @@ export default ({ navigation }) => {
|
||||
setLoading(true);
|
||||
if (isWeb) {
|
||||
const provider = new firebase.auth.GoogleAuthProvider();
|
||||
provider.addScope("profile");
|
||||
provider.addScope("email");
|
||||
provider.addScope('profile');
|
||||
provider.addScope('email');
|
||||
await firebase.auth().signInWithPopup(provider);
|
||||
await afterLoginNavigate();
|
||||
setLoading(false);
|
||||
} else {
|
||||
// Use defaults from the request; don't override with proxy here
|
||||
const result = await promptAsync();
|
||||
if (result?.type !== "success") {
|
||||
if (result?.type !== 'success') {
|
||||
// Cancelled or errored during the browser flow
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Google Login error", e?.message);
|
||||
console.log('Google Login error', e?.message);
|
||||
setTooltip({
|
||||
text: e?.message || "Connexion Google impossible. Merci de réessayer.",
|
||||
type: "error",
|
||||
text: e?.message || 'Connexion Google impossible. Merci de réessayer.',
|
||||
type: 'error',
|
||||
});
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -101,7 +99,7 @@ export default ({ navigation }) => {
|
||||
useEffect(() => {
|
||||
const handleNativeGoogleResponse = async () => {
|
||||
try {
|
||||
if (response?.type === "success") {
|
||||
if (response?.type === 'success') {
|
||||
// If using Expo proxy, tokens can be present already.
|
||||
let idToken =
|
||||
response?.authentication?.idToken || response?.params?.id_token;
|
||||
@@ -116,13 +114,13 @@ export default ({ navigation }) => {
|
||||
const clientId = request?.clientId;
|
||||
const discovery = {
|
||||
authorizationEndpoint:
|
||||
"https://accounts.google.com/o/oauth2/v2/auth",
|
||||
tokenEndpoint: "https://oauth2.googleapis.com/token",
|
||||
revocationEndpoint: "https://oauth2.googleapis.com/revoke",
|
||||
'https://accounts.google.com/o/oauth2/v2/auth',
|
||||
tokenEndpoint: 'https://oauth2.googleapis.com/token',
|
||||
revocationEndpoint: 'https://oauth2.googleapis.com/revoke',
|
||||
};
|
||||
|
||||
// Light debug: helps identify redirect/client mismatches in dev.
|
||||
console.log("Google token exchange", {
|
||||
console.log('Google token exchange', {
|
||||
clientId,
|
||||
redirectUri: request?.redirectUri,
|
||||
hasCodeVerifier: !!request?.codeVerifier,
|
||||
@@ -135,13 +133,13 @@ export default ({ navigation }) => {
|
||||
redirectUri: request?.redirectUri,
|
||||
extraParams: { code_verifier: request?.codeVerifier },
|
||||
},
|
||||
discovery
|
||||
discovery,
|
||||
);
|
||||
idToken = tokenResponse?.id_token;
|
||||
}
|
||||
|
||||
if (!idToken)
|
||||
throw new Error("Jeton Google manquant (échange/retour)");
|
||||
throw new Error('Jeton Google manquant (échange/retour)');
|
||||
|
||||
const credential =
|
||||
firebase.auth.GoogleAuthProvider.credential(idToken);
|
||||
@@ -149,10 +147,10 @@ export default ({ navigation }) => {
|
||||
await afterLoginNavigate();
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Google native sign-in error", e?.message);
|
||||
console.log('Google native sign-in error', e?.message);
|
||||
setTooltip({
|
||||
text: e?.message || "Connexion Google impossible",
|
||||
type: "error",
|
||||
text: e?.message || 'Connexion Google impossible',
|
||||
type: 'error',
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -230,8 +228,8 @@ export default ({ navigation }) => {
|
||||
<GradientButton
|
||||
title="Se connecter"
|
||||
containerStyle={{
|
||||
width: "80%",
|
||||
alignSelf: "center",
|
||||
width: '80%',
|
||||
alignSelf: 'center',
|
||||
}}
|
||||
onPress={onLogin}
|
||||
disabled={loading || !email || !password}
|
||||
@@ -245,16 +243,16 @@ export default ({ navigation }) => {
|
||||
onPress={onLoginWithGoogle}
|
||||
disabled={loading}
|
||||
/> */}
|
||||
<GoogleSigninButton
|
||||
style={{ width: "80%", height: 50, alignSelf: "center" }}
|
||||
color={GoogleSigninButton.Color.Dark}
|
||||
onPress={onLoginWithGoogle}
|
||||
disabled={loading}
|
||||
/>
|
||||
{/*<GoogleSigninButton*/}
|
||||
{/* style={{ width: "80%", height: 50, alignSelf: "center" }}*/}
|
||||
{/* color={GoogleSigninButton.Color.Dark}*/}
|
||||
{/* onPress={onLoginWithGoogle}*/}
|
||||
{/* disabled={loading}*/}
|
||||
{/*/>*/}
|
||||
|
||||
<View
|
||||
style={{
|
||||
alignItems: "center",
|
||||
alignItems: 'center',
|
||||
gap: 4,
|
||||
}}
|
||||
>
|
||||
@@ -266,7 +264,7 @@ export default ({ navigation }) => {
|
||||
fontFamily: FONT_FAMILY.HelveticaNeueRegular,
|
||||
}}
|
||||
>
|
||||
Pas encore de compte?{" "}
|
||||
Pas encore de compte?{' '}
|
||||
<Text
|
||||
style={{
|
||||
fontFamily: FONT_FAMILY.InterSemiBold,
|
||||
|
||||
Reference in New Issue
Block a user