Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

React Native passing data in auth fuction

$
0
0

im new in react native and i try to passing data from my login class to a auth function but it dont work.

This is my Auth function

function auth(username, password) {fetch('http://192.168.178.26:8000/auth/', {    method: 'POST',    headers: {'Content-Type': 'application/json',    },    body: JSON.stringify({ username, password })})    .then(res => res.json())    .then(res => {        saveToken(res.token);        console.log(res.token);        props.navigation.navigate('Home');    })    .catch(error => console.log(error));

Constructor

    constructor() {    super()    this.state = {        isReady: false,        username: '',        password: '',    }    this.auth = auth(this.state.username, this.state.password)...more code    render() {    const {password} = this.state.password;    const {username} = this.state.username;

My Text Inputs and the login button

<TextInput  placeholder='Email'  ...  value={username}/><TextInput placeholder='Password'  ...  value={password}/><TapGestureHandler><Animated.View style={style.button} ><Text style={{ ... onPress={this.auth}>Anmelden</Text>

I work on this for days now and googled hours but i cant find a solution. Can you please help me?

Best regards.


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>