-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_App.tsx
112 lines (93 loc) · 3.11 KB
/
_App.tsx
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
import { StatusBar } from "expo-status-bar";
import { ImageBackground, Text, TouchableOpacity, View } from "react-native";
import { makeRedirectUri, useAuthRequest } from "expo-auth-session";
import * as SecureStore from "expo-secure-store";
import {
Roboto_400Regular,
Roboto_700Bold,
useFonts,
} from "@expo-google-fonts/roboto";
import { BaiJamjuree_700Bold } from "@expo-google-fonts/bai-jamjuree";
import blurBg from "./src/assets/bg-blur.png";
import NLWLogo from "./src/assets/nlw-spacetime-logo.svg";
import Stripes from "./src/assets/stripes.svg";
import { styled } from "nativewind";
import { useEffect } from "react";
import { api } from "./src/lib/api";
const StyledStripes = styled(Stripes);
// Endpoint
const discovery = {
authorizationEndpoint: "https://github.com/login/oauth/authorize",
tokenEndpoint: "https://github.com/login/oauth/access_token",
revocationEndpoint:
"https://github.com/settings/connections/applications/f7319650946839d29f4f",
};
export default function App() {
const [request, response, signInWithGithub] = useAuthRequest(
{
clientId: "f7319650946839d29f4f",
scopes: ["identity"],
redirectUri: makeRedirectUri({
scheme: "nlwspacetime",
}),
},
discovery
);
const [hasLoadedFonts] = useFonts({
Roboto_400Regular,
Roboto_700Bold,
BaiJamjuree_700Bold,
});
useEffect(() => {
console.log(makeRedirectUri({
scheme: 'nlwspacetime'
}),)
if (response?.type === "success") {
const { code } = response.params;
api
.post("/register", { code, platform: 'app' })
.then((response) => {
const { token } = response.data;
SecureStore.setItemAsync("st-token-app", token);
})
.catch((err) => {
console.error(err);
});
}
}, [response]);
if (!hasLoadedFonts) return null;
return (
<ImageBackground
source={blurBg}
className="relative flex-1 items-center bg-gray-900 px-8 py-10"
imageStyle={{ position: "absolute", left: "-100%" }}
>
<StyledStripes className="absolute left-2" />
<View className="flex-1 items-center justify-center gap-6">
<NLWLogo />
<View className="space-y-2">
<Text className="text-center font-title text-2xl leading-tight text-gray-50">
Sua cápsula do tempo
</Text>
<Text className="text-center font-body text-base leading-relaxed text-gray-100">
Colecione momentos marcantes da sua jornada e compartilhe com o
mundo!
</Text>
</View>
<TouchableOpacity
activeOpacity={0.7}
className="rounded-full bg-green-500 px-5 py-2"
onPress={() => signInWithGithub()}
>
<Text className="font-alt text-sm uppercase leading-none text-black">
Cadastrar lembrança
</Text>
</TouchableOpacity>
</View>
<Text className="text-center font-body text-sm leading-relaxed text-gray-200">
Feito com 💜 no NLW da Rocketseat
</Text>
<StatusBar style="light" translucent />
</ImageBackground>
);
}