mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
39 lines
1014 B
JavaScript
39 lines
1014 B
JavaScript
// @TODO: I have abstracted this in another PR. Use that function when merged
|
|
function getApiKey () {
|
|
let AUTH_SETTINGS = localStorage.getItem('habit-mobile-settings');
|
|
|
|
if (AUTH_SETTINGS) {
|
|
AUTH_SETTINGS = JSON.parse(AUTH_SETTINGS);
|
|
|
|
if (AUTH_SETTINGS.auth && AUTH_SETTINGS.auth.apiId && AUTH_SETTINGS.auth.apiToken) {
|
|
return AUTH_SETTINGS.auth.apiToken;
|
|
}
|
|
}
|
|
}
|
|
|
|
export function goToModForm (user) {
|
|
if (!user) return;
|
|
|
|
const apiKey = getApiKey();
|
|
if (!apiKey) return;
|
|
|
|
const tenMins = 10 * 60 * 1000;
|
|
let dateTime;
|
|
dateTime = new Date();
|
|
dateTime.setTime(dateTime.getTime() + tenMins);
|
|
const expires = `expires=${dateTime.toGMTString()}`;
|
|
|
|
const email = encodeURIComponent(user.auth.local.email);
|
|
|
|
const userData = {
|
|
email,
|
|
profileName: user.profile.name,
|
|
uuid: user._id,
|
|
apiKey,
|
|
};
|
|
|
|
document.cookie = `habiticauserdata=${JSON.stringify(userData)};${expires};domain=.habitica.com;path=/`;
|
|
|
|
window.location.href = 'https://contact.habitica.com';
|
|
}
|