Javascript 带导航的登录身份验证

Javascript 带导航的登录身份验证,javascript,reactjs,react-native,ecmascript-6,jsx,Javascript,Reactjs,React Native,Ecmascript 6,Jsx,我是新来的。。我只为一个餐厅应用程序制作了一个UI,现在将所有静态组件转换为动态组件。。。我的第一步>如何进行登录验证以及何时登录导航特定屏幕 (强)弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱

我是新来的。。我只为一个餐厅应用程序制作了一个UI,现在将所有静态组件转换为动态组件。。。我的第一步>如何进行登录验证以及何时登录导航特定屏幕

(强)弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱ــــ

Login.js

import React, { Component } from 'react';
import { Image, View, TouchableOpacity } from 'react-native';

import { Container, Content, Form, Item, Label, Linking, Icon, Text, Button, Input } from 'native-base';
import styles from './../../styles/Login/login'
import PasswordTextBox from './passwordInput'
import {
  useNavigation,
  useRoute,
  useFocusEffect,
  useNavigationState
} from '@react-navigation/native';

import {NavigationContainer} from '@react-navigation/native'

LoginForm = () => {

return (

  <Container style={styles.containerStl} >
  <Content showsVerticalScrollIndicator={false}>
    <View style={styles.viewStl}>
        <Text style={styles.titleStl}>Sign In</Text>
      <Form style={styles.formStl} >
        <Item style={styles.formStl} stackedLabel>
            <Label style={styles.labelStl}>Email ID</Label>
            <Input regular    
            placeholder='sample@emailid.com'
            placeholderTextColor="#e3e3e3" 
            style={styles.inputStl} 
        />
        </Item>
        <Item style={styles.formStl} stackedLabel>
            <Label style={styles.labelStl}>Password</Label>
            <PasswordTextBox icon="lock" label="New Password"  />

          </Item>
        <Text style={styles.forgotStl} onPress={() => navigation.navigate('Forgot Password', { screenName: "Forgot Password" })}>Forgot Password?</Text>
        <Button style={styles.btnStl} onPress={() => navigation.navigate('Profile View', { screenName: "Profile View" })}>
          <Text style={styles.centerTxt}>Sign In</Text>
        </Button>
        
        <Text style={styles.notMember} onPress={() => navigation.navigate('Sign Up', { screenName: "Sign Up" })} >Not yet a member, <Text style={styles.notSignup} >Sign Up</Text></Text>
      </Form>
      </View>

    </Content>
  </Container>

);
  }

  export default LoginForm;
import React, { useEffect, Component } from 'react';
import {  StatusBar } from 'react-native';


import {NavigationContainer} from '@react-navigation/native'
import {createStackNavigator} from '@react-navigation/stack'
import {createMaterialBottomTabNavigator} from '@react-navigation/material-bottom-tabs'
import {createMaterialTopTabNavigator} from '@react-navigation/material-top-tabs'


import LoginForm from './components/Login/login'

const Tab = createBottomTabNavigator();


const LoginStack = createStackNavigator();

function LoginStackScreen() {
  return (
    <LoginStack.Navigator
    screenOptions={{
      headerShown: false
    }}>
      <LoginStack.Screen name="Login" component={LoginForm} />
      <LoginStack.Screen name="Registeration" component={RegForm} />
      <LoginStack.Screen name="Forgot Password" component={ForgotPass} />
      <LoginStack.Screen name="Corp Login" component={corpLogin} />
      <LoginStack.Screen name="Corp Registration" component={CorpRegForm} />
      <LoginStack.Screen name="Corp Forgot Password" component={CorpforgotPass} />
    </LoginStack.Navigator>
  );
}

createHomeStack = () =>
 <Stack.Navigator   screenOptions={{
     headerShown: false
   }}
 >
  <Stack.Screen name="Lines Portal" component={LinesPortal} />
 </Stack.Navigator>



export default class App extends Component {
  render() {
     return (
      <LoginForm />
     )
  }
}
import React,{Component}来自'React';
从“react native”导入{Image,View,TouchableOpacity};
从“本机基础”导入{容器、内容、表单、项目、标签、链接、图标、文本、按钮、输入};
从“../../../styles/Login/Login”导入样式
从“./passwordInput”导入PasswordTextBox
进口{
使用导航,
用户路由,
useFocusEffect,
使用导航状态
}来自'@react导航/native';
从'@react navigation/native'导入{NavigationContainer}
LoginForm=()=>{
返回(
登录
电子邮件ID
密码
导航('忘记密码',{屏幕名称:“忘记密码”})}>忘记密码?
navigation.navigate('Profile View',{screenName:'Profile View})}>
登录
navigation.navigate('Sign-Up',{screenName:'Sign-Up}}}>尚未成为会员,请注册
);
}
导出默认登录信息;
(强)弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱ــــ

我正在使用react导航进行路由

App.js

import React, { Component } from 'react';
import { Image, View, TouchableOpacity } from 'react-native';

import { Container, Content, Form, Item, Label, Linking, Icon, Text, Button, Input } from 'native-base';
import styles from './../../styles/Login/login'
import PasswordTextBox from './passwordInput'
import {
  useNavigation,
  useRoute,
  useFocusEffect,
  useNavigationState
} from '@react-navigation/native';

import {NavigationContainer} from '@react-navigation/native'

LoginForm = () => {

return (

  <Container style={styles.containerStl} >
  <Content showsVerticalScrollIndicator={false}>
    <View style={styles.viewStl}>
        <Text style={styles.titleStl}>Sign In</Text>
      <Form style={styles.formStl} >
        <Item style={styles.formStl} stackedLabel>
            <Label style={styles.labelStl}>Email ID</Label>
            <Input regular    
            placeholder='sample@emailid.com'
            placeholderTextColor="#e3e3e3" 
            style={styles.inputStl} 
        />
        </Item>
        <Item style={styles.formStl} stackedLabel>
            <Label style={styles.labelStl}>Password</Label>
            <PasswordTextBox icon="lock" label="New Password"  />

          </Item>
        <Text style={styles.forgotStl} onPress={() => navigation.navigate('Forgot Password', { screenName: "Forgot Password" })}>Forgot Password?</Text>
        <Button style={styles.btnStl} onPress={() => navigation.navigate('Profile View', { screenName: "Profile View" })}>
          <Text style={styles.centerTxt}>Sign In</Text>
        </Button>
        
        <Text style={styles.notMember} onPress={() => navigation.navigate('Sign Up', { screenName: "Sign Up" })} >Not yet a member, <Text style={styles.notSignup} >Sign Up</Text></Text>
      </Form>
      </View>

    </Content>
  </Container>

);
  }

  export default LoginForm;
import React, { useEffect, Component } from 'react';
import {  StatusBar } from 'react-native';


import {NavigationContainer} from '@react-navigation/native'
import {createStackNavigator} from '@react-navigation/stack'
import {createMaterialBottomTabNavigator} from '@react-navigation/material-bottom-tabs'
import {createMaterialTopTabNavigator} from '@react-navigation/material-top-tabs'


import LoginForm from './components/Login/login'

const Tab = createBottomTabNavigator();


const LoginStack = createStackNavigator();

function LoginStackScreen() {
  return (
    <LoginStack.Navigator
    screenOptions={{
      headerShown: false
    }}>
      <LoginStack.Screen name="Login" component={LoginForm} />
      <LoginStack.Screen name="Registeration" component={RegForm} />
      <LoginStack.Screen name="Forgot Password" component={ForgotPass} />
      <LoginStack.Screen name="Corp Login" component={corpLogin} />
      <LoginStack.Screen name="Corp Registration" component={CorpRegForm} />
      <LoginStack.Screen name="Corp Forgot Password" component={CorpforgotPass} />
    </LoginStack.Navigator>
  );
}

createHomeStack = () =>
 <Stack.Navigator   screenOptions={{
     headerShown: false
   }}
 >
  <Stack.Screen name="Lines Portal" component={LinesPortal} />
 </Stack.Navigator>



export default class App extends Component {
  render() {
     return (
      <LoginForm />
     )
  }
}
import React,{useffect,Component}来自'React';
从“react native”导入{StatusBar};
从'@react navigation/native'导入{NavigationContainer}
从“@react navigation/stack”导入{createStackNavigator}
从“@react navigation/material bottom tabs”导入{createMaterialBottomTabNavigator}
从“@react navigation/material top tabs”导入{createMaterialTopTabNavigator}
从“./components/Login/Login”导入LoginForm
const Tab=createBottomTabNavigator();
const LoginStack=createStackNavigator();
函数LoginStackScreen(){
返回(
);
}
createHomeStack=()=>
导出默认类应用程序扩展组件{
render(){
返回(
)
}
}
(强)弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱弱ــــ

正如我之前所说,我是一个新手,没有人关注我,也没有人寻求帮助来指导我。。所以我只有你们了


另一个问题。。如何将“构造函数”和“this”与箭头函数组件一起使用?

如何将“构造函数”和“this”与箭头函数组件一起使用

you use the useState hook to do the same thing. For example:
const [isLoggedIn, setIsLoggedIn] = React.useState(false);
这行代码将isLoggedIn的初始值设置为false,然后创建函数setIsLoggedIn来设置该值。i、 e

setIsLoggedIn(true);
这相当于下面的一个类组件

this.setState({isLoggedIn: true});
您的代码中缺少很多东西,因此我将使用React Navigation总结身份验证流程中的方法。作为参考,你可以看看这个

首先,您需要有一个状态(首选使用react context或redux存储变量),表示用户是否登录。让我们使用isLoggedIn

isLoggedIn ? (
  <>
    <Stack.Screen name="Home" component={HomeScreen} />
    <Stack.Screen name="Profile" component={ProfileScreen} />
  </>
) : (
  <>
    <Stack.Screen name="SignIn" component={SignInScreen} />
    <Stack.Screen name="SignUp" component={SignUpScreen} />
    <Stack.Screen name="ResetPassword" component={ResetPassword} />
  </>
);
isLoggedIn?(
) : (
);
然后在登录屏幕中,根据登录进程的状态,将同一状态变量isLoggedIn修改为true/false。当变量isLoggedIn为true时,将呈现Home和Profile组件,而不是Signin和Signup组件