React Native:删除 Expo Cookie
React Native: Remove Expo Cookies
我正在构建一个 Expo/React 本机应用程序,我在其中使用提取和凭据 (cookie) 登录服务器。
代码运行正常,如下所示:
login = async (email, password) => {
try {
var body = JSON.stringify({ email, password });
const response = await fetch('http://10.0.2.2/login', {
method: 'POST',
credentials: 'include',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: username,
password: password
})
});
if(response.hasOwnProperty('accessToken'))
{
console.log('login successfull');
console.log(response);
}
else if(response.hasOwnProperty('error'))
{
console.log('login failed');
console.log(response)
}
}
catch(e) {
console.log('error: ' + e);
}
};
我的问题是,当我停止应用程序时,React Native 不会注销。我不想通过 API 调用手动注销。
有没有像 React Web 中那样的方法,我只需从 Chrome 中删除 cookie,然后我就注销了?
如果你正在使用 expo 那么你可以试试 :
expo r -c
这将清除您项目的缓存和 运行 expo
您可以使用 RCTNetworking
中的 clearCookies
函数来清除 cookie:
const RCTNetworking = require('RCTNetworking');
RCTNetworking.clearCookies((result) => {
console.log(result) //true if successfully cleared
});
我可以确认它在 Android 和 expo 上有效。对于 iOS,我认为它已通过此 https://github.com/facebook/react-native/pull/9264 修复。
我正在构建一个 Expo/React 本机应用程序,我在其中使用提取和凭据 (cookie) 登录服务器。
代码运行正常,如下所示:
login = async (email, password) => {
try {
var body = JSON.stringify({ email, password });
const response = await fetch('http://10.0.2.2/login', {
method: 'POST',
credentials: 'include',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: username,
password: password
})
});
if(response.hasOwnProperty('accessToken'))
{
console.log('login successfull');
console.log(response);
}
else if(response.hasOwnProperty('error'))
{
console.log('login failed');
console.log(response)
}
}
catch(e) {
console.log('error: ' + e);
}
};
我的问题是,当我停止应用程序时,React Native 不会注销。我不想通过 API 调用手动注销。
有没有像 React Web 中那样的方法,我只需从 Chrome 中删除 cookie,然后我就注销了?
如果你正在使用 expo 那么你可以试试 :
expo r -c
这将清除您项目的缓存和 运行 expo
您可以使用 RCTNetworking
中的 clearCookies
函数来清除 cookie:
const RCTNetworking = require('RCTNetworking');
RCTNetworking.clearCookies((result) => {
console.log(result) //true if successfully cleared
});
我可以确认它在 Android 和 expo 上有效。对于 iOS,我认为它已通过此 https://github.com/facebook/react-native/pull/9264 修复。