AUTORYZACJA DO GOOOOOGLA DZIALA
This commit is contained in:
@@ -14,13 +14,19 @@
|
|||||||
"backgroundColor": "#ffffff"
|
"backgroundColor": "#ffffff"
|
||||||
},
|
},
|
||||||
"ios": {
|
"ios": {
|
||||||
"supportsTablet": true
|
"supportsTablet": true,
|
||||||
|
"bundleIdentifier": "com.hamx.ArtisanConnect"
|
||||||
},
|
},
|
||||||
"android": {
|
"android": {
|
||||||
"adaptiveIcon": {
|
"adaptiveIcon": {
|
||||||
"foregroundImage": "./assets/adaptive-icon.png",
|
"foregroundImage": "./assets/adaptive-icon.png",
|
||||||
"backgroundColor": "#ffffff"
|
"backgroundColor": "#ffffff"
|
||||||
}
|
},
|
||||||
|
"permissions": [
|
||||||
|
"android.permission.RECORD_AUDIO",
|
||||||
|
"android.permission.CAMERA"
|
||||||
|
],
|
||||||
|
"package": "com.hamx.ArtisanConnect"
|
||||||
},
|
},
|
||||||
"web": {
|
"web": {
|
||||||
"favicon": "./assets/favicon.png"
|
"favicon": "./assets/favicon.png"
|
||||||
@@ -40,6 +46,12 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"expo-web-browser"
|
"expo-web-browser"
|
||||||
]
|
],
|
||||||
|
"extra": {
|
||||||
|
"router": {},
|
||||||
|
"eas": {
|
||||||
|
"projectId": "7a0d8bc8-938f-4d2a-babb-945faee13429"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, {useState} from 'react';
|
import React, {useEffect, useState} from 'react';
|
||||||
import {StyleSheet, ActivityIndicator, SafeAreaView, View} from 'react-native';
|
import {StyleSheet, ActivityIndicator, SafeAreaView, View} from 'react-native';
|
||||||
import {useAuthStore} from '@/store/authStore';
|
import {useAuthStore} from '@/store/authStore';
|
||||||
import {useRouter, Link} from 'expo-router';
|
import {useRouter, Link} from 'expo-router';
|
||||||
@@ -15,12 +15,27 @@ import {ArrowRightIcon} from "@/components/ui/icon"
|
|||||||
import {Divider} from '@/components/ui/divider';
|
import {Divider} from '@/components/ui/divider';
|
||||||
import {Ionicons} from "@expo/vector-icons";
|
import {Ionicons} from "@expo/vector-icons";
|
||||||
|
|
||||||
|
import * as WebBrowser from 'expo-web-browser';
|
||||||
|
import * as Google from "expo-auth-session/providers/google";
|
||||||
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||||
|
|
||||||
|
WebBrowser.maybeCompleteAuthSession();
|
||||||
|
|
||||||
|
// client_id ios 936418008320-ohefdfcebd41f6oa2o8phh1mgj9s49sl.apps.googleusercontent.com
|
||||||
|
// android 936418008320-d8dfjph5e4r28fcm1rbdfbh5phmbg03d.apps.googleusercontent.com
|
||||||
|
|
||||||
export default function Login() {
|
export default function Login() {
|
||||||
const [email, setEmail] = useState('');
|
const [email, setEmail] = useState('');
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
const {signIn, isLoading} = useAuthStore();
|
const {signIn, isLoading} = useAuthStore();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
const [request, response, promptAsync] = Google.useAuthRequest({
|
||||||
|
androidClientId: "936418008320-d8dfjph5e4r28fcm1rbdfbh5phmbg03d.apps.googleusercontent.com",
|
||||||
|
iosClientId: "936418008320-ohefdfcebd41f6oa2o8phh1mgj9s49sl.apps.googleusercontent.com",
|
||||||
|
webClientId: "936418008320-btdngtlfnjac1p67guje72m9el5q59a7.apps.googleusercontent.com"
|
||||||
|
})
|
||||||
|
|
||||||
const handleInternalLogin = async () => {
|
const handleInternalLogin = async () => {
|
||||||
if (!email || !password) {
|
if (!email || !password) {
|
||||||
alert('Proszę wprowadzić email i hasło.');
|
alert('Proszę wprowadzić email i hasło.');
|
||||||
@@ -36,6 +51,42 @@ export default function Login() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
handleGoogleLogin();
|
||||||
|
}, [response]);
|
||||||
|
|
||||||
|
const handleGoogleLogin = async () => {
|
||||||
|
const user = await AsyncStorage.getItem("@user");
|
||||||
|
if (!user) {
|
||||||
|
if(response?.type === "success") {
|
||||||
|
await getUserInfo(response.authentication.accessToken)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Set the user in the auth store
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getUserInfo = async (token) => {
|
||||||
|
if(!token) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const response = await fetch("https://www.googleapis.com/userinfo/v2/me",
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const user = await response.json();
|
||||||
|
console.log("Pobrano informacje o użytkowniku:", user);
|
||||||
|
await AsyncStorage.setItem("@user", JSON.stringify(user));
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Błąd podczas pobierania informacji o użytkowniku:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
@@ -82,7 +133,7 @@ export default function Login() {
|
|||||||
</Text>
|
</Text>
|
||||||
<Divider flex={1}/>
|
<Divider flex={1}/>
|
||||||
</HStack>
|
</HStack>
|
||||||
<Button size="sm">
|
<Button size="sm" onPress={() => promptAsync()}>
|
||||||
<Ionicons name="logo-google" color="#fff"/>
|
<Ionicons name="logo-google" color="#fff"/>
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
21
ArtisanConnect/eas.json
Normal file
21
ArtisanConnect/eas.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"cli": {
|
||||||
|
"version": ">= 16.8.0",
|
||||||
|
"appVersionSource": "remote"
|
||||||
|
},
|
||||||
|
"build": {
|
||||||
|
"development": {
|
||||||
|
"developmentClient": true,
|
||||||
|
"distribution": "internal"
|
||||||
|
},
|
||||||
|
"preview": {
|
||||||
|
"distribution": "internal"
|
||||||
|
},
|
||||||
|
"production": {
|
||||||
|
"autoIncrement": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"submit": {
|
||||||
|
"production": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,11 +53,12 @@
|
|||||||
"react-native-gesture-handler": "~2.24.0",
|
"react-native-gesture-handler": "~2.24.0",
|
||||||
"react-native-reanimated": "~3.17.4",
|
"react-native-reanimated": "~3.17.4",
|
||||||
"react-native-safe-area-context": "5.4.0",
|
"react-native-safe-area-context": "5.4.0",
|
||||||
"react-native-screens": "~4.10.0",
|
"react-native-screens": "~4.11.1",
|
||||||
"react-native-svg": "15.11.2",
|
"react-native-svg": "15.11.2",
|
||||||
"react-native-web": "~0.20.0",
|
"react-native-web": "~0.20.0",
|
||||||
"tailwindcss": "^3.4.17",
|
"tailwindcss": "^3.4.17",
|
||||||
"zustand": "^5.0.3"
|
"zustand": "^5.0.3",
|
||||||
|
"expo-crypto": "~14.1.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.20.0",
|
"@babel/core": "^7.20.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user