Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (val.trim() === '') {
return false;
}
return true;
},
});
}
const answers = await prompt(questions);
const data = {
username: username || answers.username,
password: password || answers.password,
};
let user = await UserManager.loginAsync('user-pass', data);
if (user) {
console.log(`\nSuccess. You are now logged in as ${chalk.green(user.username)}.`);
return user;
} else {
throw new Error('Unexpected Error: No user returned from the API');
}
}
async function _loginAsCorrectUserAsync(): Promise {
const username = process.env.EXPO_HOME_DEV_ACCOUNT_USERNAME;
if (!username) {
throw new Error('EXPO_HOME_DEV_ACCOUNT_USERNAME must be set in your environment.');
}
const password = process.env.EXPO_HOME_DEV_ACCOUNT_PASSWORD;
if (!password) {
throw new Error('EXPO_HOME_DEV_ACCOUNT_PASSWORD must be set in your environment.');
}
await UserManager.loginAsync('user-pass', {
username,
password,
});
}
export async function ensureUserLoggedIn(userData: IUserData) {
const currentUser = await UserManager.getCurrentUserAsync();
if (currentUser) {
return currentUser;
} else if (!userData.username || !userData.password) {
throw new ErrorWithProgramHelp('Please provide username and password');
} else {
try {
return await UserManager.loginAsync('user-pass', userData);
} catch (err) {
throw new Error('Failed to log in with provided username and password');
}
}
}