mattermost-mobile/app/utils/security.js
Elias Nahum 298067ab65
Update react-native-cookies & react-native-webview + always use defaultDataStore (#5452)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-06-15 18:40:35 -04:00

24 lines
773 B
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Client4} from '@client/rest';
import CookieManager from '@react-native-cookies/cookies';
export function setCSRFFromCookie(url) {
return new Promise((resolve) => {
CookieManager.get(url, false).then((cookies) => {
const token = cookies.MMCSRF;
if (token) {
let value = null;
if (typeof token === 'object' && Object.prototype.hasOwnProperty.call(token, 'value')) {
value = token.value;
} else {
value = token;
}
Client4.setCSRF(value);
}
resolve();
});
});
}