Skip to content

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

Description

@Alexis1989

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;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions