import { LOGIN, REMEMBER_TOKEN, TOKEN_BOX } from './constants';
import { clearNote, postError } from './note';
import { buttonClearStyles, selectRemember, selectToken } from './utils';
import { addCommentForm } from './wrapper';
const login = `
`;
const storeToken = (token, state) => {
const { localStorage } = window;
const rememberMe = selectRemember().checked;
// All the browsers we support have localStorage, so let's silently fail
// and go on with the rest of the functionality.
try {
if (rememberMe) {
localStorage.setItem('token', token);
}
} finally {
state.token = token;
}
};
const authorizeUser = state => {
// Clear any old errors
clearNote(TOKEN_BOX);
const token = selectToken().value;
if (!token) {
/* eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings */
postError('Please enter your token.', TOKEN_BOX);
return;
}
storeToken(token, state);
addCommentForm();
};
export { authorizeUser, login };