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';
|
import { atom } from 'recoil';
|
||||||
|
|
||||||
export const authFlowUserEmailState = atom<string>({
|
export const authFlowUserEmailState = atom({
|
||||||
key: 'authFlowUserEmailState',
|
key: 'authFlowUserEmailState',
|
||||||
default: '',
|
default: process.env.NODE_ENV === 'development' ? 'tim@apple.dev' : '',
|
||||||
});
|
});
|
||||||
|
|||||||
@ -30,7 +30,9 @@ export function Index() {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
useMockData();
|
useMockData();
|
||||||
|
|
||||||
const [, setAuthFlowUserEmail] = useRecoilState(authFlowUserEmailState);
|
const [authFlowUserEmail, setAuthFlowUserEmail] = useRecoilState(
|
||||||
|
authFlowUserEmailState,
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (hasAccessToken()) {
|
if (hasAccessToken()) {
|
||||||
@ -71,7 +73,7 @@ export function Index() {
|
|||||||
</PrimaryButton>
|
</PrimaryButton>
|
||||||
<HorizontalSeparator />
|
<HorizontalSeparator />
|
||||||
<TextInput
|
<TextInput
|
||||||
value=""
|
value={authFlowUserEmail}
|
||||||
placeholder="Email"
|
placeholder="Email"
|
||||||
onChange={(value) => setAuthFlowUserEmail(value)}
|
onChange={(value) => setAuthFlowUserEmail(value)}
|
||||||
fullWidth={true}
|
fullWidth={true}
|
||||||
|
|||||||
@ -29,13 +29,21 @@ const StyledButtonContainer = styled.div`
|
|||||||
margin-top: ${({ theme }) => theme.spacing(7)};
|
margin-top: ${({ theme }) => theme.spacing(7)};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const StyledErrorContainer = styled.div`
|
||||||
|
color: ${({ theme }) => theme.red};
|
||||||
|
`;
|
||||||
|
|
||||||
export function PasswordLogin() {
|
export function PasswordLogin() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const prefillPassword =
|
||||||
|
process.env.NODE_ENV === 'development' ? 'applecar2025' : '';
|
||||||
|
|
||||||
const [authFlowUserEmail, setAuthFlowUserEmail] = useRecoilState(
|
const [authFlowUserEmail, setAuthFlowUserEmail] = useRecoilState(
|
||||||
authFlowUserEmailState,
|
authFlowUserEmailState,
|
||||||
);
|
);
|
||||||
|
const [internalPassword, setInternalPassword] = useState(prefillPassword);
|
||||||
const [internalPassword, setInternalPassword] = useState('');
|
const [formError, setFormError] = useState('');
|
||||||
|
|
||||||
const userLogin = useCallback(async () => {
|
const userLogin = useCallback(async () => {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
@ -60,7 +68,10 @@ export function PasswordLogin() {
|
|||||||
}
|
}
|
||||||
await getTokensFromLoginToken(loginToken.token);
|
await getTokensFromLoginToken(loginToken.token);
|
||||||
navigate('/');
|
navigate('/');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
const errorData = await response.json();
|
||||||
|
setFormError(errorData.message);
|
||||||
}, [authFlowUserEmail, internalPassword, navigate]);
|
}, [authFlowUserEmail, internalPassword, navigate]);
|
||||||
|
|
||||||
useHotkeys(
|
useHotkeys(
|
||||||
@ -107,6 +118,9 @@ export function PasswordLogin() {
|
|||||||
</PrimaryButton>
|
</PrimaryButton>
|
||||||
</StyledButtonContainer>
|
</StyledButtonContainer>
|
||||||
</StyledInputContainer>
|
</StyledInputContainer>
|
||||||
|
{formError && (
|
||||||
|
<StyledErrorContainer>{formError}</StyledErrorContainer>
|
||||||
|
)}
|
||||||
</StyledContentContainer>
|
</StyledContentContainer>
|
||||||
</Modal>
|
</Modal>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -60,15 +60,15 @@ export class AuthService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
assert(user, "This user doens't exist", NotFoundException);
|
assert(user, "This user doesn't exist", NotFoundException);
|
||||||
assert(user.passwordHash, 'Something wrong happened', ForbiddenException);
|
assert(user.passwordHash, 'Incorrect login method', ForbiddenException);
|
||||||
|
|
||||||
const isValid = await compareHash(
|
const isValid = await compareHash(
|
||||||
challengeInput.password,
|
challengeInput.password,
|
||||||
user.passwordHash,
|
user.passwordHash,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(isValid, 'Something wrong happened', ForbiddenException);
|
assert(isValid, 'Wrong password', ForbiddenException);
|
||||||
|
|
||||||
return user;
|
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
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { passwordHash: _, ...user } = data;
|
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