-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
216 lines (188 loc) · 6.13 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import * as React from "react";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { RootNavigator } from "./Navigation/RootNavigator";
import { AuthenticatedUserProvider } from "./providers";
const MyStack = () => {
return (
<AuthenticatedUserProvider>
<SafeAreaProvider>
<RootNavigator />
</SafeAreaProvider>
</AuthenticatedUserProvider>
);
};
export default MyStack;
//
//Google login
//
// import { StatusBar } from "expo-status-bar";
// import { StyleSheet, Text, View, Image, Button, Platform } from "react-native";
// import * as Google from "expo-auth-session/providers/google";
// import { useEffect, useState } from "react";
// import AsyncStorage from "@react-native-async-storage/async-storage";
// import * as AuthSession from "expo-auth-session";
// // expo add expo-auth-session expo-random expo-dev-client
// // expo add @react-native-async-storage/async-storage
// /*
// For testing expo-auth-session on iOS we need a standalone app
// which is why we install expo-dev-client
// If you don't have eas installed then install using the following command:
// npm install -g eas-cli
// eas login
// eas build:configure
// Build for local development on iOS or Android:
// eas build -p ios --profile development --local
// OR
// eas build -p android --profile development --local
// May need to install the following to build locally (which allows debugging)
// npm install -g yarn
// brew install fastlane
// After building install on your device:
// For iOS (simulator): https://docs.expo.dev/build-reference/simulators/
// For Android: https://docs.expo.dev/build-reference/apk/
// Run on installed app:
// expo start --dev-client
// */
// export default function App() {
// const [userInfo, setUserInfo] = useState();
// const [auth, setAuth] = useState();
// const [requireRefresh, setRequireRefresh] = useState(false);
// const [request, response, promptAsync] = Google.useAuthRequest({
// androidClientId:
// "403889420981-fg6vamcijn74rodun3o9n3b1uga6s08h.apps.googleusercontent.com",
// expoClientId:
// "403889420981-d4kv0a0hpgas95c4dkr8dd5vge11cl0t.apps.googleusercontent.com",
// });
// useEffect(() => {
// console.log(response, "test1");
// if (response?.type === "success") {
// setAuth(response.authentication);
// const persistAuth = async () => {
// await AsyncStorage.setItem(
// "auth",
// JSON.stringify(response.authentication)
// );
// };
// persistAuth();
// }
// }, [response]);
// useEffect(() => {
// const getPersistedAuth = async () => {
// const jsonValue = await AsyncStorage.getItem("auth");
// if (jsonValue != null) {
// const authFromJson = JSON.parse(jsonValue);
// setAuth(authFromJson);
// console.log(authFromJson);
// setRequireRefresh(
// !AuthSession.TokenResponse.isTokenFresh({
// expiresIn: authFromJson.expiresIn,
// issuedAt: authFromJson.issuedAt,
// })
// );
// }
// };
// getPersistedAuth();
// }, []);
// const getUserData = async () => {
// let userInfoResponse = await fetch(
// "https://www.googleapis.com/userinfo/v2/me",
// {
// headers: { Authorization: `Bearer ${auth.accessToken}` },
// }
// );
// userInfoResponse.json().then((data) => {
// console.log(data);
// setUserInfo(data);
// });
// };
// const showUserData = () => {
// if (userInfo) {
// return (
// <View style={styles.userInfo}>
// <Image source={{ uri: userInfo.picture }} style={styles.profilePic} />
// <Text>Welcome {userInfo.name}</Text>
// <Text>{userInfo.email}</Text>
// </View>
// );
// }
// };
// const getClientId = () => {
// if (Platform.OS === "ios") {
// return "139581308140-imf4dv4bogf4aj945eosqvnett4mp06e.apps.googleusercontent.com";
// } else if (Platform.OS === "android") {
// return "139581308140-n3ebiqnid8tmskvneo7lck2cku8va9s3.apps.googleusercontent.com";
// } else {
// console.log("Invalid platform - not handled");
// }
// };
// const refreshToken = async () => {
// const clientId = getClientId();
// console.log(auth);
// const tokenResult = await AuthSession.refreshAsync(
// {
// clientId: clientId,
// refreshToken: auth.refreshToken,
// },
// {
// tokenEndpoint: "https://www.googleapis.com/oauth2/v4/token",
// }
// );
// tokenResult.refreshToken = auth.refreshToken;
// console.log(tokenResult, "tokenresult");
// setAuth(tokenResult);
// await AsyncStorage.setItem("auth", JSON.stringify(tokenResult));
// setRequireRefresh(false);
// };
// if (requireRefresh) {
// return (
// <View style={styles.container}>
// <Text>Token requires refresh...</Text>
// <Button title="Refresh Token" onPress={refreshToken} />
// </View>
// );
// }
// const logout = async () => {
// await AuthSession.revokeAsync(
// {
// token: auth.accessToken,
// },
// {
// revocationEndpoint: "https://oauth2.googleapis.com/revoke",
// }
// );
// setAuth(undefined);
// setUserInfo(undefined);
// await AsyncStorage.removeItem("auth");
// };
// return (
// <View style={styles.container}>
// {showUserData()}
// <Button
// title={auth ? "Get User Data" : "Login"}
// onPress={
// auth
// ? getUserData
// : () => promptAsync({ useProxy: false, showInRecents: true })
// }
// />
// {auth ? <Button title="Logout" onPress={logout} /> : undefined}
// <StatusBar style="auto" />
// </View>
// );
// }
// const styles = StyleSheet.create({
// container: {
// flex: 1,
// backgroundColor: "#fff",
// alignItems: "center",
// justifyContent: "center",
// },
// profilePic: {
// width: 50,
// height: 50,
// },
// userInfo: {
// alignItems: "center",
// justifyContent: "center",
// },
// });