首页 > 解决方案 > Firebase 的电话验证确认(代码)不是函数错误

问题描述

import React,{useEffect, useState} from 'react';
import {
    View,
} from 'react-native';
import Circle from '../components/Circle';
import MainContainer from '../components/MainContainer';
import AuthContents from '../components/AuthContents';


const Code = ({navigation, route}) => {

    const [confirm, setConfirm] = useState(null)

    useEffect( () => {
        console.log('Code')
     OTP()
    }, [])

    async function OTP()
    {
        try{
            const confirmation = await route.params.confirmation
            setConfirm(confirmation)
        }catch(e)
        {
            alert(JSON.stringify(e))
        }
    }

      const CodeAuthenticate = async (value) => {
        console.log(confirm)
        if (value.length === 6) {
            //
            //Send code
            //
           
                const result = await confirm.confirm(value);
                console.log(result)
                if (result.additionalUserInfo.isNewUser) {
                    navigation.navigate('UserData', { uid: result.user.uid })
                } else {
                    navigation.navigate('ChatList')
                   
                }

        }
    }

    return (

        <MainContainer>
            <View style={{ flex: 1 }}>
                <Circle />
                <AuthContents length = {6} placeholderValue='Enter Code' onPress={CodeAuthenticate} />
            </View>
        </MainContainer>



    )


}

export default Code;

错误

可能的未处理承诺拒绝(id:0):TypeError:confirm.confirm 不是函数。(在 'confirm.confirm(value)' 中,'confirm.confirm' 未定义)

CodeAuthenticate$@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:119464:64 tryCatch@http://localhost:8081/index.bundle?platform= android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:7708:23 invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:7881:32 tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:7708:23 invoke@http://localhost:8081/index.bundle?platform=android&dev =true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:7781:30 http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:7811:19 tryCallTwo@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:28586:9 doResolve@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:28750:25 Promise@http://localhost:8081/index.bundle?platform=android&dev =true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:28609:14 callInvokeWithMethodAndArg@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:7810:33 enqueue @http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:7815:157 async@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:7832:69 CodeAuthenticate@http://localhost: 8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:119452:40 onPress@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly =false&runModule=true:116179:31 _performTransitionSideEffects@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:61638:22 _receiveSignal@http://localhost:8081 /index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:61580:45 onResponderRelease@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:61487:34 invokeGuardedCallbackProd@http://localhost:8081/ index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:9638:21 invokeGuardedCallback@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule =true:9742:42 invokeGuardedCallbackAndCatchFirstError@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:9746:36 executeDispatch@http://localhost:8081/index .bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:9818:48 executeDispatchesInOrder@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:9838:26 executeDispatchesAndRelease@http://localhost: 8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:11091:35 forEach@[native code] forEachAccumulated@http://localhost:8081/index.bundle?platform=android&dev=true&minify =false&app=com.chatu&modulesOnly=false&runModule=true:10361:22 runEventsInBatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:11115:27 runExtractedPluginEventsInBatch@http ://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:11195:25 http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:11170:42 batchedUpdates$1@http ://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:22280:20 batchedUpdates@http://localhost:8081/index.bundle?platform=android&dev=true&minify= false&app=com.chatu&modulesOnly=false&runModule=true:11077:36 _receiveRootNodeIDEvent@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:11169:23 receiveTouches@http: //localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:11223:34 __callFunction@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:3262:36 http://localhost:8081/ index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:2986:31 __guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule =true:3213:15 callFunctionReturnFlushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:2985:21 callFunctionReturnFlushedQueue@[本机代码]dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:3262:36 http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:2986:31 __guard@ http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:3213:15 callFunctionReturnFlushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify =false&app=com.chatu&modulesOnly=false&runModule=true:2985:21 callFunctionReturnFlushedQueue@[本机代码]dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:3262:36 http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:2986:31 __guard@ http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:3213:15 callFunctionReturnFlushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify =false&app=com.chatu&modulesOnly=false&runModule=true:2985:21 callFunctionReturnFlushedQueue@[本机代码]31 __guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:3213:15 callFunctionReturnFlushedQueue@http://localhost:8081/index.bundle?platform= android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:2985:21 callFunctionReturnFlushedQueue@[本机代码]31 __guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:3213:15 callFunctionReturnFlushedQueue@http://localhost:8081/index.bundle?platform= android&dev=true&minify=false&app=com.chatu&modulesOnly=false&runModule=true:2985:21 callFunctionReturnFlushedQueue@[本机代码]

标签: reactjsfirebasereact-nativereact-navigation

解决方案


推荐阅读