Improve auth and seeds (#352)
* Improve seeds * Autofill password on local environment * Fix PR --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { atom } from 'recoil';
|
||||
|
||||
export const authFlowUserEmailState = atom<string>({
|
||||
export const authFlowUserEmailState = atom({
|
||||
key: 'authFlowUserEmailState',
|
||||
default: '',
|
||||
default: process.env.NODE_ENV === 'development' ? 'tim@apple.dev' : '',
|
||||
});
|
||||
|
||||
@ -30,7 +30,9 @@ export function Index() {
|
||||
const theme = useTheme();
|
||||
useMockData();
|
||||
|
||||
const [, setAuthFlowUserEmail] = useRecoilState(authFlowUserEmailState);
|
||||
const [authFlowUserEmail, setAuthFlowUserEmail] = useRecoilState(
|
||||
authFlowUserEmailState,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (hasAccessToken()) {
|
||||
@ -71,7 +73,7 @@ export function Index() {
|
||||
</PrimaryButton>
|
||||
<HorizontalSeparator />
|
||||
<TextInput
|
||||
value=""
|
||||
value={authFlowUserEmail}
|
||||
placeholder="Email"
|
||||
onChange={(value) => setAuthFlowUserEmail(value)}
|
||||
fullWidth={true}
|
||||
|
||||
@ -29,13 +29,21 @@ const StyledButtonContainer = styled.div`
|
||||
margin-top: ${({ theme }) => theme.spacing(7)};
|
||||
`;
|
||||
|
||||
const StyledErrorContainer = styled.div`
|
||||
color: ${({ theme }) => theme.red};
|
||||
`;
|
||||
|
||||
export function PasswordLogin() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const prefillPassword =
|
||||
process.env.NODE_ENV === 'development' ? 'applecar2025' : '';
|
||||
|
||||
const [authFlowUserEmail, setAuthFlowUserEmail] = useRecoilState(
|
||||
authFlowUserEmailState,
|
||||
);
|
||||
|
||||
const [internalPassword, setInternalPassword] = useState('');
|
||||
const [internalPassword, setInternalPassword] = useState(prefillPassword);
|
||||
const [formError, setFormError] = useState('');
|
||||
|
||||
const userLogin = useCallback(async () => {
|
||||
const response = await fetch(
|
||||
@ -60,7 +68,10 @@ export function PasswordLogin() {
|
||||
}
|
||||
await getTokensFromLoginToken(loginToken.token);
|
||||
navigate('/');
|
||||
return;
|
||||
}
|
||||
const errorData = await response.json();
|
||||
setFormError(errorData.message);
|
||||
}, [authFlowUserEmail, internalPassword, navigate]);
|
||||
|
||||
useHotkeys(
|
||||
@ -107,6 +118,9 @@ export function PasswordLogin() {
|
||||
</PrimaryButton>
|
||||
</StyledButtonContainer>
|
||||
</StyledInputContainer>
|
||||
{formError && (
|
||||
<StyledErrorContainer>{formError}</StyledErrorContainer>
|
||||
)}
|
||||
</StyledContentContainer>
|
||||
</Modal>
|
||||
</>
|
||||
|
||||
@ -60,15 +60,15 @@ export class AuthService {
|
||||
},
|
||||
});
|
||||
|
||||
assert(user, "This user doens't exist", NotFoundException);
|
||||
assert(user.passwordHash, 'Something wrong happened', ForbiddenException);
|
||||
assert(user, "This user doesn't exist", NotFoundException);
|
||||
assert(user.passwordHash, 'Incorrect login method', ForbiddenException);
|
||||
|
||||
const isValid = await compareHash(
|
||||
challengeInput.password,
|
||||
user.passwordHash,
|
||||
);
|
||||
|
||||
assert(isValid, 'Something wrong happened', ForbiddenException);
|
||||
assert(isValid, 'Wrong password', ForbiddenException);
|
||||
|
||||
return user;
|
||||
}
|
||||
@ -80,7 +80,7 @@ export class AuthService {
|
||||
},
|
||||
});
|
||||
|
||||
assert(data, "This user doens't exist", NotFoundException);
|
||||
assert(data, "This user doesn't exist", NotFoundException);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { passwordHash: _, ...user } = data;
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user