Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can’t get the token again only after I delete the user data #28788

Closed
Alexis1989 opened this issue Apr 29, 2020 · 3 comments
Closed

I can’t get the token again only after I delete the user data #28788

Alexis1989 opened this issue Apr 29, 2020 · 3 comments
Labels
Needs: Triage 🔍 Resolution: For Stack Overflow A question for Stack Overflow. Applying this label will cause issue to be closed. Resolution: Locked This issue was locked by the bot.

Comments

@Alexis1989
Copy link

I can not get the token again. But after deleting the user data in the application, I can get it again

React Native version:

System:
OS: macOS 10.15.4
CPU: (4) x64 Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz
Memory: 232.47 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 13.13.0 - /usr/local/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.14.4 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.1 - /Users/alexey/.rvm/rubies/ruby-2.6.1/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK: Not Found
IDEs:
Android Studio: 3.6 AI-192.7142.36.36.6308749
Xcode: 11.4.1/11E503a - /usr/bin/xcodebuild
Languages:
Java: 11.0.2 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: ^4.8.0 => 4.8.0
react: 16.11.0 => 16.11.0
react-native: 0.62.2 => 0.62.2
npmGlobalPackages:
react-native: Not Found

Steps To Reproduce

  1. I created a project.
  2. I sent a request to the server to receive a token. I recieved it.
  3. I sent a request to remove the token from the server.
  4. I try to get the token again, but I get null.
  5. After that, I went into the application information and deleted the user data.

After that, I was able to get a token again

20-04-29-19-01-50

Expected Results

I do not want to delete user data manually each time to get a token. It is not comfortable

This code works in version 0.59.9, but does not work on 0.62.2

Code example:

import React, { Component } from 'react';
import {
  SafeAreaView,
  View,
  Text,
  TextInput,
  TouchableOpacity,
  StyleSheet
} from 'react-native';

class App extends Component {
  state = { login: 'login', password: 'password', };

  getToken = async (login, password) => {
    const res = await fetch('https://mysite.com/api/v1/sessions', {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        'Cache-Control': 'no-cache, no-store, must-revalidate',
        'Pragma': 'no-cache',
        'Expires': 0
      },
      body: JSON.stringify({
        user: { login: login, password: password, },
      }),
    });

    let jsonRes = await res.json();

    console.warn(`status = ${res.ok}`);
    console.warn(`I got token = ${jsonRes.data.auth_token}`);

    return await jsonRes;
  };

  getUserToken = async (login, password) => {
    const res = await this.getToken(login, password)
      .then((results) => {
        this.setState({ token: results.data.auth_token })
      });

    return res;
  }

  deleteWithToken = async () => {
    const res = await fetch(`https://mysite.com/api/v1/sessions/?auth_token=${this.state.token}`,
      {
        method: 'DELETE',
        headers: {
          'Cache-Control': 'no-cache, no-store, must-revalidate',
          'Pragma': 'no-cache',
          'Expires': 0
        },
      }).then((results) => {
        console.warn("I removed token");
      });
  }

  render() {
    return (
      <SafeAreaView>
        <View>
          <TextInput style={styles.input} placeholder={'login'} defaultValue={this.state.login} />
          <TextInput
            style={styles.input}
            placeholder={'password'}
            defaultValue={this.state.password}
            secureTextEntry={true}
          />
          <TouchableOpacity style={styles.button} onPress={() => this.getUserToken(this.state.login, this.state.password)}>
            <Text style={styles.btnText}>Sign in</Text>
          </TouchableOpacity>
          <TouchableOpacity style={styles.button} onPress={() => this.deleteWithToken()}>
            <Text style={styles.btnText}>Sign out</Text>
          </TouchableOpacity>
        </View>
      </SafeAreaView>
    );
  }
}

export default App;
@reyanshmishra
Copy link

this bug is not related to ReactNative framework, you can ask this type of questions on http://stackoverflow.com/

@fabOnReact
Copy link
Contributor

reyanshmishra is right.

@safaiyeh safaiyeh added the Resolution: For Stack Overflow A question for Stack Overflow. Applying this label will cause issue to be closed. label Aug 8, 2020
@github-actions
Copy link

github-actions bot commented Aug 8, 2020

We are using GitHub issues exclusively to track bugs in the core React Native library. Please try asking over on Stack Overflow as it is better suited for this type of question.

@github-actions github-actions bot closed this as completed Aug 8, 2020
@facebook facebook locked as resolved and limited conversation to collaborators Oct 1, 2021
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs: Triage 🔍 Resolution: For Stack Overflow A question for Stack Overflow. Applying this label will cause issue to be closed. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants