Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const loadSession = async user => {
let path = utils.buildPath(user.hash)
let device = new api.Device(user.username)
let storage = new api.CookieFileStorage(path)
if (storage) {
return new api.Session(device, storage)
} else {
let file = await createSessionFile(user)
if (file) console.log('Session File Created')
return false
}
}
return new Promise((resolve, reject) => {
if (!session) {
const device = utils.getDevice();
const storage = utils.getCookieStorage();
if (!device || !storage) {
return resolve({ isLoggedIn: false });
}
session = new Client.Session(device, storage);
}
session.getAccountId()
.then(() => resolve({ isLoggedIn: true, session }))
.catch(Client.Exceptions.CookieNotValidError, () => resolve({ isLoggedIn: false }))
});
}
const loadSession = user => {
let path = utils.buildPath(user.hash)
let device = new api.Device(user.username)
let storage = new api.CookieFileStorage(path)
return new api.Session(device, storage)
}
return new Promise((resolve, reject) => {
if (!session) {
const device = utils.getDevice();
const storage = utils.getCookieStorage();
if (!device || !storage) {
return resolve({ isLoggedIn: false });
}
session = new Client.Session(device, storage);
}
session.getAccountId()
.then(() => resolve({ isLoggedIn: true, session }))
.catch(Client.Exceptions.CookieNotValidError, () => resolve({ isLoggedIn: false }))
});
}
return new Promise((resolve, reject) => {
const device = utils.getDevice(username);
const storage = utils.getCookieStorage(`${username}.json`);
const session = new Client.Session(device, storage);
const request = new Client.Request(session);
request.setMethod('POST')
.setUrl(Client.CONSTANTS.API_ENDPOINT + "accounts/two_factor_login/")
.generateUUID()
.setData({
username: username,
verification_code: code,
two_factor_identifier: twoFactorIdentifier,
trust_this_device: trustThisDevice,
verification_method: verificationMethod,
})
.signPayload()
.send()
.then(() => session.loginFlow())
.then(() => resolve(session))
.catch(reject)