You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native中AuthProvider登录异常:输入正确信息未完成登录

React Native AuthProvider登录校验异常问题

我在React Native中使用AuthProvider实现用户登录校验,输入正确账号信息后登录流程未完成,仅弹出一条警告提示,且未抛出任何错误信息。相关代码及警告如下:

登录页面代码

import React, { useState, useContext } from "react";
import * as Yup from "yup";
import { Formik } from "formik";
import auth from '@react-native-firebase/auth';
import LinearGradient from 'react-native-linear-gradient';
import Color from 'react-native-material-color';
import { AuthContext } from '../../Navigation/AuthProvider';
import {
Text,
View,
StyleSheet,
SafeAreaView,
Image,
TextInput,
Button,
ScrollView,
TouchableOpacity
} from 'react-native';

export default login = ({navigation})=>{

  const { useContext } = React;
  const {login} = useContext(AuthContext);

  const signInvalidationSchema =Yup.object().shape({

    email:Yup
    .string()
    .required('boş geçilemez')
    .email('geçerli bir email adresi yaziniz'),
    
    password:Yup
    .string()
    .required('boş geçilemez').min(6,({min})=>'sifre en az '+ min +'karakter olmalıdır!')
    })

    return (

      <SafeAreaView style={styles.container}>
        <ScrollView>
          <View style={styles.top}>
            <Image
              style={{
                width: 150,
                height: 200,
                resizeMode: 'contain'
              }}
              source={
                require('../../image/logo.png')
              }
            />
            <Text style={styles.textLogo}>AGER FORUM</Text>
          </View>
          <Formik
            initialValues={{
              email: '',
              password: ''
            }}
            onSubmit={(values)=>login(values.email,values.password)}
            validationSchema={signInvalidationSchema}
          >
            {
              ({
                values,
                handleSubmit,
                isValid,
                isSubmitting,
                errors,
                handleBlur,
                handleChange
              }) => (

                <View style={styles.mid}>
                  <View style={styles.box}>
                    <View style={styles.textBox}>
                      <Text style={styles.textMid}>E-mail</Text>
                    </View>
                    <View style={styles.inputView}>
                      <LinearGradient
                        colors={['#840ec1', '#a643d9', '#d743d9', '#be1dc0', '#a00ba2', '#8a04a6']}
                        start={{ x: 0.0, y: 1.0 }} end={{ x: 1.0, y: 1.0 }}
                        style={styles.grediant}
                      >

                        <TextInput
                          values={values.email}
                          onChangeText={handleChange('email')}
                          onBlur={handleBlur('email')}
                          placeholder={"Email"}
                          placeholderTextColor={"#302000"}
                          style={styles.input}
                          keyboardType="email-address"

                        />
                        
                      </LinearGradient>
                      {(errors.email) && <Text style={styles.error}>{errors.email}</Text>}
                    </View>

                  </View>
                  <View style={styles.box}>
                    <View style={styles.textBox}>
                      <Text style={styles.textMid}>Şifre</Text>
                    </View>
                    <View style={styles.inputView}>
                      <LinearGradient
                        colors={['#840ec1', '#a643d9', '#d743d9', '#be1dc0', '#a00ba2', '#8a04a6']}
                        start={{ x: 0.0, y: 1.0 }} end={{ x: 1.0, y: 1.0 }}
                        style={styles.grediant}
                      >
                        <TextInput

                          values={values.password}
                          onChangeText={handleChange('password')}
                          onBlur={handleBlur('password')}
                          placeholder={"Password"}
                          placeholderTextColor={"#302000"}
                          style={styles.input}
                          secureTextEntry={true}

                        />
                       
                      </LinearGradient>
                      {(errors.password) && <Text style={styles.error}>{errors.password}</Text>}
                    </View>
                  </View>
                  <TouchableOpacity
                    disabled={!isValid }
                    onPress={handleSubmit}
                    style={styles.button}
                  >
                    <Text style={styles.button_text}>Sign in My Account</Text>
                  </TouchableOpacity>
                  <View style={styles.kayitText}>
                    <TouchableOpacity
                      onPress={() =>navigation.navigate('Register')}

                    >
                      <Text style={{ color: 'white', fontSize: 14, fontWeight: 'bold' }}>Kayit Ol</Text>
                    </TouchableOpacity>
                  </View>
                </View>
              )
            }
          </Formik>
          <View style={styles.bot}>

          </View>
        </ScrollView>
      </SafeAreaView>

    );
  
}

AuthProvider代码

import { View, Text } from 'react-native'
import React,{useState,useEffect,createContext} from 'react'
import auth from '@react-native-firebase/auth'

export const AuthContext = createContext({}); 

export const AuthProvider = ({children}) => {
    console.log('first');
    const [user, setUser] = useState(null);
    
  return (
    <AuthContext.Provider
    
    value={{
        user,
        setUser,
        login:async(email,password)=>{
            try {
                await auth().signInWithEmailAndPassword(email,password)
                .then(async result =>{
                    if(!result.user.emailVerified){
                        result.user.sendEmailVerification();
                        alert('Lütfen emailinize gelen maili onaylayınız')
                    }
                })
            } catch (error) {
                console.log('errorlogin',error),
                console.log('user',user)
            }
        },

        register:async(email,password,name)=>{
            try {
                await auth().createUserWithEmailAndPassword(email,password)
                .then(async result =>{

                    result.user.updateProfile({
                        displayName:name
                    })
                        result.user.sendEmailVerification();
                        alert('Kayıt işlemi bittikten sonra lütfen emailinize gelen maili onaylayınız')
                    
                })
            } catch (error) {
                console.log(error),
                console.log('user',user)
            }
        },

        resetPass:async(email)=>{
            try {
                await auth().sendPasswordResetEmail(email);
                alert('sifre sıfırlama kodunuz emaile gönderilmiştir')
            } catch (error) {
                console.log(error)
            }
        },

        signOut:async()=>{
            try {
                await auth().signOut();
                alert('çıkış başarılı')
            } catch (error) {
                console.log(error)
            }
        },

    }}

    >{children}
    </AuthContext.Provider>
  )
}

警告信息

警告截图

我知道这只是一条警告,但所有配置看起来都正确,登录却未成功完成,且未收到任何错误提示。


内容的提问来源于stack exchange,提问作者TURAN BİCAV

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 01:55:20