Skip to content

Commit

Permalink
Salvando o IP na storage
Browse files Browse the repository at this point in the history
  • Loading branch information
dgleyramos1 committed Apr 11, 2023
1 parent 263d3d3 commit 63406ea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
3 changes: 0 additions & 3 deletions src/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,17 @@ export function AuhtProvider({children}: AuhtProviderProps){

if(Object.keys(hasIp).length > 0){
api.defaults.baseURL = `http://${hasIp}`
console.log(hasIp)
setIp(hasIp);
}
if(Object.keys(hasUser).length > 0){
if(validateToken(hasUser.token)){
api.defaults.headers.common['Authorization'] = `Bearer ${hasUser.token}`
setUser({token: hasUser.token})
setLoading(false);

return;
}
signOut()
}

setLoading(false);
}
getUser()
Expand Down
42 changes: 35 additions & 7 deletions src/pages/SignIn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import {View,
ActivityIndicator
} from 'react-native';
import { AuthContext } from '../../contexts/AuthContext';
import {Ionicons} from '@expo/vector-icons'


export default function SignIn(){
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [ip, setIp] = useState("");
const [port, setPort] = useState("");
const [eye, setEye] = useState(true)

const {signIn, loadingAuth, addIpAddress, haveIpAddress} = useContext(AuthContext);

Expand All @@ -33,6 +35,10 @@ export default function SignIn(){
await addIpAddress({ip : ipAdress});
}

function handleEyePassword(){
setEye(!eye);
}


return(

Expand All @@ -48,13 +54,19 @@ export default function SignIn(){
value={username}
onChangeText={setUsername}
/>
<TextInput
placeholder='Digite sua senha'
style={styles.input}
placeholderTextColor="#f0f0f0"
value={password}
onChangeText={setPassword}
/>
<View style={styles.inputArea}>
<TextInput
placeholder='Digite sua senha'
style={[styles.input, {width: '85%', marginBottom: 0}]}
placeholderTextColor="#f0f0f0"
value={password}
onChangeText={setPassword}
secureTextEntry={eye}
/>
<TouchableOpacity style={styles.icon} onPress={handleEyePassword}>
<Ionicons name='eye' color="#fff" size={25}/>
</TouchableOpacity>
</View>

<TouchableOpacity
style={styles.button}
Expand Down Expand Up @@ -121,6 +133,17 @@ const styles = StyleSheet.create({
paddingVertical: 32,
paddingHorizontal: 14
},
inputArea: {
flexDirection: 'row',
width: '100%',
backgroundColor: '#101026',
borderRadius: 4,
alignItems: 'center',
justifyContent: 'space-between',
paddingVertical: 8,
marginBottom: 12,
height: 40
},
input: {
width: '100%',
height: 40,
Expand All @@ -145,5 +168,10 @@ const styles = StyleSheet.create({
title: {
color: '#fff',
fontSize: 16
},
icon: {
width: '15%',
justifyContent: 'center',
alignItems: 'center'
}
});

0 comments on commit 63406ea

Please sign in to comment.