Can't get token - using async storage method - react native(Expo) The Next CEO of Stack OverflowHide keyboard in react-nativeWhat is the difference between using constructor vs getInitialState in React / React Native?React Native android build failed. SDK location not foundWhat is the difference between React Native and React?What is the difference between Expo and React Native?Not using the Expo fork of react-nativeReact Native Expo Camerareact-native expo issue: check method of `SceneView`undefined-is-not-an-object-evaluating-this-state-datasource.mapExpo, React Native Async Storage resets after hot reload?
How do I go from 300 unfinished/half written blog posts, to published posts?
Grabbing quick drinks
What can we do to stop prior company from asking us questions?
Is a stroke of luck acceptable after a series of unfavorable events?
MAZDA 3 2006 (UK) - poor acceleration then takes off at 3250 revs
What happens if you roll doubles 3 times then land on "Go to jail?"
Shade part of a Venn diagram
Why did we only see the N-1 starfighters in one film?
Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?
India just shot down a satellite from the ground. At what altitude range is the resulting debris field?
Does the Brexit deal have to be agreed by both Houses?
When airplanes disconnect from a tanker during air to air refueling, why do they bank so sharply to the right?
Anatomically Correct Mesopelagic Aves
Is it safe to use c_str() on a temporary string?
Need some help with wall behind rangetop
Failed to fetch jessie backports repository
When Does an Atlas Uniquely Define a Manifold?
How long to clear the 'suck zone' of a turbofan after start is initiated?
Implement the Thanos sorting algorithm
Why does standard notation not preserve intervals (visually)
Trouble understanding the speech of overseas colleagues
How to get regions to plot as graphics
% symbol leads to superlong (forever?) compilations
Should I tutor a student who I know has cheated on their homework?
Can't get token - using async storage method - react native(Expo)
The Next CEO of Stack OverflowHide keyboard in react-nativeWhat is the difference between using constructor vs getInitialState in React / React Native?React Native android build failed. SDK location not foundWhat is the difference between React Native and React?What is the difference between Expo and React Native?Not using the Expo fork of react-nativeReact Native Expo Camerareact-native expo issue: check method of `SceneView`undefined-is-not-an-object-evaluating-this-state-datasource.mapExpo, React Native Async Storage resets after hot reload?
I'm working on a feedback form and I'm having trouble getting token from the server after I logged into a random user account. This is my code:
getToken function:
getToken = async () =>
try
const value = await AsyncStorage.getItem("token");
this.setState( userToken: value );
catch (error)
console.log("Error retrieving data" + error);
;
submit function:
postFeedback(userToken, title, content, to_id, category)
fetch(
"https://deployattendancemanagement.herokuapp.com/api/feedback/send",
method: "POST",
headers:
"Content-Type": "application/x-www-form-urlencoded"
,
body: JSON.stringify(
token: userToken,
title: title,
content: content,
to_id: to_id,
category: category
)
)
.then(response => response.json())
.then(res =>
if (typeof res.result != "success")
console.log(res.message);
Alert.alert(
"Oops !",
"Something went wrong",
[
text: "OK",
onPress: () => console.log("Cancel Pressed"),
style: "cancel"
],
cancelable: false
);
else
console.log("success");
Alert.alert(
"Yay !",
"Something went right",
[
text: "OK",
onPress: () => console.log("Send feedback"),
style: "cancel"
],
cancelable: false
);
)
.catch(error =>
console.error(error);
);
Button:
<Button
full
onPress=() =>
this.postFeedback(
this.state.userToken,
this.state.title,
this.state.content,
this.state.to_id,
this.state.category
)
>
<Text>SUBMIT</Text>
</Button>
But after I pressed the button, the title and content were not sent and it gives me this error: No Token Provided. Please help, I'm very new at react-native programming.
react-native expo
add a comment |
I'm working on a feedback form and I'm having trouble getting token from the server after I logged into a random user account. This is my code:
getToken function:
getToken = async () =>
try
const value = await AsyncStorage.getItem("token");
this.setState( userToken: value );
catch (error)
console.log("Error retrieving data" + error);
;
submit function:
postFeedback(userToken, title, content, to_id, category)
fetch(
"https://deployattendancemanagement.herokuapp.com/api/feedback/send",
method: "POST",
headers:
"Content-Type": "application/x-www-form-urlencoded"
,
body: JSON.stringify(
token: userToken,
title: title,
content: content,
to_id: to_id,
category: category
)
)
.then(response => response.json())
.then(res =>
if (typeof res.result != "success")
console.log(res.message);
Alert.alert(
"Oops !",
"Something went wrong",
[
text: "OK",
onPress: () => console.log("Cancel Pressed"),
style: "cancel"
],
cancelable: false
);
else
console.log("success");
Alert.alert(
"Yay !",
"Something went right",
[
text: "OK",
onPress: () => console.log("Send feedback"),
style: "cancel"
],
cancelable: false
);
)
.catch(error =>
console.error(error);
);
Button:
<Button
full
onPress=() =>
this.postFeedback(
this.state.userToken,
this.state.title,
this.state.content,
this.state.to_id,
this.state.category
)
>
<Text>SUBMIT</Text>
</Button>
But after I pressed the button, the title and content were not sent and it gives me this error: No Token Provided. Please help, I'm very new at react-native programming.
react-native expo
I also see you are using both promises and async awaits syntax. I suggest to stick to one of them as that approach might just clear up some things
– stephanmantel
Mar 8 at 13:51
add a comment |
I'm working on a feedback form and I'm having trouble getting token from the server after I logged into a random user account. This is my code:
getToken function:
getToken = async () =>
try
const value = await AsyncStorage.getItem("token");
this.setState( userToken: value );
catch (error)
console.log("Error retrieving data" + error);
;
submit function:
postFeedback(userToken, title, content, to_id, category)
fetch(
"https://deployattendancemanagement.herokuapp.com/api/feedback/send",
method: "POST",
headers:
"Content-Type": "application/x-www-form-urlencoded"
,
body: JSON.stringify(
token: userToken,
title: title,
content: content,
to_id: to_id,
category: category
)
)
.then(response => response.json())
.then(res =>
if (typeof res.result != "success")
console.log(res.message);
Alert.alert(
"Oops !",
"Something went wrong",
[
text: "OK",
onPress: () => console.log("Cancel Pressed"),
style: "cancel"
],
cancelable: false
);
else
console.log("success");
Alert.alert(
"Yay !",
"Something went right",
[
text: "OK",
onPress: () => console.log("Send feedback"),
style: "cancel"
],
cancelable: false
);
)
.catch(error =>
console.error(error);
);
Button:
<Button
full
onPress=() =>
this.postFeedback(
this.state.userToken,
this.state.title,
this.state.content,
this.state.to_id,
this.state.category
)
>
<Text>SUBMIT</Text>
</Button>
But after I pressed the button, the title and content were not sent and it gives me this error: No Token Provided. Please help, I'm very new at react-native programming.
react-native expo
I'm working on a feedback form and I'm having trouble getting token from the server after I logged into a random user account. This is my code:
getToken function:
getToken = async () =>
try
const value = await AsyncStorage.getItem("token");
this.setState( userToken: value );
catch (error)
console.log("Error retrieving data" + error);
;
submit function:
postFeedback(userToken, title, content, to_id, category)
fetch(
"https://deployattendancemanagement.herokuapp.com/api/feedback/send",
method: "POST",
headers:
"Content-Type": "application/x-www-form-urlencoded"
,
body: JSON.stringify(
token: userToken,
title: title,
content: content,
to_id: to_id,
category: category
)
)
.then(response => response.json())
.then(res =>
if (typeof res.result != "success")
console.log(res.message);
Alert.alert(
"Oops !",
"Something went wrong",
[
text: "OK",
onPress: () => console.log("Cancel Pressed"),
style: "cancel"
],
cancelable: false
);
else
console.log("success");
Alert.alert(
"Yay !",
"Something went right",
[
text: "OK",
onPress: () => console.log("Send feedback"),
style: "cancel"
],
cancelable: false
);
)
.catch(error =>
console.error(error);
);
Button:
<Button
full
onPress=() =>
this.postFeedback(
this.state.userToken,
this.state.title,
this.state.content,
this.state.to_id,
this.state.category
)
>
<Text>SUBMIT</Text>
</Button>
But after I pressed the button, the title and content were not sent and it gives me this error: No Token Provided. Please help, I'm very new at react-native programming.
react-native expo
react-native expo
edited Mar 8 at 13:42
Mahdi NBA
187
187
asked Mar 7 at 16:30
thinh-phanthinh-phan
13
13
I also see you are using both promises and async awaits syntax. I suggest to stick to one of them as that approach might just clear up some things
– stephanmantel
Mar 8 at 13:51
add a comment |
I also see you are using both promises and async awaits syntax. I suggest to stick to one of them as that approach might just clear up some things
– stephanmantel
Mar 8 at 13:51
I also see you are using both promises and async awaits syntax. I suggest to stick to one of them as that approach might just clear up some things
– stephanmantel
Mar 8 at 13:51
I also see you are using both promises and async awaits syntax. I suggest to stick to one of them as that approach might just clear up some things
– stephanmantel
Mar 8 at 13:51
add a comment |
2 Answers
2
active
oldest
votes
You have not called getToken()
function in your code. That would be the problem here.
add a comment |
From what I understand, you are not saving the token. You need to save it before you can retrieve it. It would be helpful if you could share the code where you receive the token but here's the general syntax of saving something to AsyncStorage. Also make sure you call the getToken()
function.
saveToken = async () =>
let token = 'something';
await AsyncStorage.setItem('key', token);
;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55048615%2fcant-get-token-using-async-storage-method-react-nativeexpo%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have not called getToken()
function in your code. That would be the problem here.
add a comment |
You have not called getToken()
function in your code. That would be the problem here.
add a comment |
You have not called getToken()
function in your code. That would be the problem here.
You have not called getToken()
function in your code. That would be the problem here.
edited Mar 9 at 17:52
Bhargav Rao♦
30.9k2092114
30.9k2092114
answered Mar 8 at 13:11
Mahdi NBAMahdi NBA
187
187
add a comment |
add a comment |
From what I understand, you are not saving the token. You need to save it before you can retrieve it. It would be helpful if you could share the code where you receive the token but here's the general syntax of saving something to AsyncStorage. Also make sure you call the getToken()
function.
saveToken = async () =>
let token = 'something';
await AsyncStorage.setItem('key', token);
;
add a comment |
From what I understand, you are not saving the token. You need to save it before you can retrieve it. It would be helpful if you could share the code where you receive the token but here's the general syntax of saving something to AsyncStorage. Also make sure you call the getToken()
function.
saveToken = async () =>
let token = 'something';
await AsyncStorage.setItem('key', token);
;
add a comment |
From what I understand, you are not saving the token. You need to save it before you can retrieve it. It would be helpful if you could share the code where you receive the token but here's the general syntax of saving something to AsyncStorage. Also make sure you call the getToken()
function.
saveToken = async () =>
let token = 'something';
await AsyncStorage.setItem('key', token);
;
From what I understand, you are not saving the token. You need to save it before you can retrieve it. It would be helpful if you could share the code where you receive the token but here's the general syntax of saving something to AsyncStorage. Also make sure you call the getToken()
function.
saveToken = async () =>
let token = 'something';
await AsyncStorage.setItem('key', token);
;
answered Mar 9 at 19:08
fsocietyfsociety
9619
9619
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55048615%2fcant-get-token-using-async-storage-method-react-nativeexpo%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I also see you are using both promises and async awaits syntax. I suggest to stick to one of them as that approach might just clear up some things
– stephanmantel
Mar 8 at 13:51