Skip to content

Commit

Permalink
Merge pull request #38 from dsc-sookmyung/feature/auth
Browse files Browse the repository at this point in the history
[#1] style: move login button to introduction screen
  • Loading branch information
hee-suh authored Mar 20, 2022
2 parents cef53b2 + 01f880f commit cc70511
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 126 deletions.
10 changes: 1 addition & 9 deletions react-native/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { theme } from './core/theme';

import { AuthProvider } from './contexts/Auth';

import LoginScreen from './screens/LoginScreen';
import JoinScreen from './screens/JoinScreen';
import HomeScreen from './screens/HomeScreen';
import TranslateScreen from './screens/TranslateScreen';
Expand Down Expand Up @@ -65,15 +64,8 @@ export default function App() {
<NativeBaseProvider theme={nativeBaseTheme}>
<NavigationContainer>
<Stack.Navigator
initialRouteName={isFirstRun == "true" ? "Introduction" : "Login"}
initialRouteName="Introduction"
>
<Stack.Screen
name="Login"
component={LoginScreen}
options={{
headerShown: false,
}}
/>
<Stack.Screen
name="Join"
component={JoinScreen}
Expand Down
55 changes: 50 additions & 5 deletions react-native/screens/IntroductionScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import React, { useState, useEffect } from 'react';
import type { Navigation } from '../types';
import { StyleSheet, View, Image, SafeAreaView, TouchableHighlight } from 'react-native';
import { StyleSheet, View, Image, SafeAreaView, TouchableHighlight, Alert } from 'react-native';
import { Text } from 'native-base'
import { theme } from '../core/theme';
import Swiper from 'react-native-swiper';
import AsyncStorage from '@react-native-async-storage/async-storage';
import * as WebBrowser from 'expo-web-browser';
import * as Google from 'expo-auth-session/providers/google';
import { GOOGLE_CLIENT_ID_WEB } from '@env';
import { useAuth } from '../contexts/Auth';
import env from 'react-native-dotenv';

WebBrowser.maybeCompleteAuthSession();


export default function HomeScreen({ navigation }: Navigation) {
const [request, response, promptAsync] = Google.useAuthRequest({
expoClientId: GOOGLE_CLIENT_ID_WEB,
webClientId: GOOGLE_CLIENT_ID_WEB,
})
const auth = useAuth();

useEffect(() => {
const storeData = async () => {
try {
Expand All @@ -17,8 +30,35 @@ export default function HomeScreen({ navigation }: Navigation) {
}
}
storeData();
})

});

useEffect(() => {
if (response?.type === 'success') {
const { authentication } = response;

if (authentication) {
auth.signIn(authentication?.accessToken);
}
else {
Alert.alert("Authentication failed. Please try again.");
}
}
else {
console.log('fail',response)
}
}, [response]);

useEffect(() => {
if (auth?.authData?.uroleType === 'GUEST') {
navigation.navigate('Join');
} else if (auth?.authData?.uroleType === 'USER') {
navigation.navigate('Home');
}
}, [auth?.authData]);

const onLoginPressed = () => {
navigation.navigate('Home');
};

return (
<SafeAreaView style={styles.container}>
Expand Down Expand Up @@ -49,9 +89,14 @@ export default function HomeScreen({ navigation }: Navigation) {
<Text fontSize="md" style={styles.description}>
Now you're ready! Let's start NotiNote with your Google account. NotiNote will register the events in your Google Calendar.
</Text>
<TouchableHighlight style={styles.startButton} onPress={() => navigation.navigate('Home')}>
<TouchableHighlight
style={styles.startButton}
onPress={() => {
promptAsync();
}}
>
<Text fontWeight={600} style={styles.buttonStyle}>
Start NotiNote
Sign In With Google
</Text>
</TouchableHighlight>
</View>
Expand Down
112 changes: 0 additions & 112 deletions react-native/screens/LoginScreen.tsx

This file was deleted.

0 comments on commit cc70511

Please sign in to comment.