auth.js
setTimeout을 걸어줘서 로그인 api처럼 동작하게 만들어줌
const EMAIL = 'my@email.com';
const PASSWORD = '1234';
export const signIn = (email, password) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (email === EMAIL && password === PASSWORD) {
resolve(email);
} else {
reject('The Email or password is wrong');
}
}, 1000);
});
};
그 후 submit 시
const onSubmit = async () => {
if (!disabled && !isLoading) {
Keyboard.dismiss();
setisLoading(true);
try {
const data = await signIn(email, password);
console.log(data);
} catch (e) {
console.log(e);
}
setisLoading(false);
}
};
위와 같이 해주면 됨.
다만 여기서 isLoading state를 바꿔주면서 동작함
그래서 중간에 재요청을 막음
로그인 실패시 Alert
catch (e) {
Alert.alert(e);
}
title전달은 변수로
Alert.alert('SignIn ERRor', e);
첫번째 파라미터가 title임
세번째 파라미터는 버튼임
Alert.alert('SignIn ERRor', e, [
{
text: 'default',
onPress: () => {
console.log('default');
},
},
{
text: 'cancel',
onPress: () => {
console.log('cancel');
},
},
{
text: 'done',
onPress: () => {
console.log('done');
},
},
]);