Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async function(userObject = {id: defaultUserId}, performsNonLearnerFunction = false) {
const userId = (userObject && 'id' in userObject) ? userObject.id : defaultUserId;
const jwtObject = {
'user_id': userId
};
if (performsNonLearnerFunction) {
jwtObject['performs_non_learner_function'] = true;
}
const encodedData = window.btoa('') + '.' + window.btoa(JSON.stringify(jwtObject)) + '.';
const token = {
jwt: encodedData
};
const { server } = getContext();
await authenticateSession(token);
if (userObject) {
const properties = Object.assign({id: userId}, userObject);
const user = server.create('user', properties);
server.create('authentication', {id: user.id, user});
return user;
}
return null;
}
export function authenticateUser(attrs = {}) {
let expiresAt = new Date().getTime() + 600000;
return authenticateSession(merge({
name: 'hradmin',
roles: ['System Administrator', 'admin', 'user'],
expires_at: expiresAt,
role: 'System Administrator',
prefix: 'p1'
}, attrs));
}