-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into task/OV-5-JWT-token
- Loading branch information
Showing
30 changed files
with
2,310 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { | ||
GetObjectCommand, | ||
PutObjectCommand, | ||
S3Client, | ||
} from '@aws-sdk/client-s3'; | ||
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'; | ||
|
||
import { type BaseConfig } from '~/common/config/base-config.package.js'; | ||
|
||
class FileService { | ||
private config: BaseConfig; | ||
private client: S3Client; | ||
private bucketName: string; | ||
private cfDistributionId: string; | ||
|
||
public constructor(config: BaseConfig) { | ||
this.config = config; | ||
|
||
this.client = this.initClient(); | ||
this.bucketName = this.config.ENV.AWS.S3.BUCKET_NAME; | ||
this.cfDistributionId = this.config.ENV.AWS.CLOUDFRONT.DOMAIN_ID; | ||
} | ||
|
||
private initClient(): S3Client { | ||
return new S3Client({ | ||
credentials: { | ||
accessKeyId: this.config.ENV.AWS.ACCESS_KEY_ID, | ||
secretAccessKey: this.config.ENV.AWS.SECRET_ACCESS_KEY, | ||
}, | ||
region: this.config.ENV.AWS.S3.REGION, | ||
}); | ||
} | ||
|
||
public uploadFile = async ( | ||
buffer: Buffer, | ||
fileName: string, | ||
): Promise<void> => { | ||
const command = new PutObjectCommand({ | ||
Bucket: this.bucketName, | ||
Key: fileName, | ||
Body: buffer, | ||
}); | ||
|
||
await this.client.send(command); | ||
}; | ||
|
||
public getFileUrl = async (fileName: string): Promise<string> => { | ||
const getFileObject = new GetObjectCommand({ | ||
Bucket: this.bucketName, | ||
Key: fileName, | ||
}); | ||
|
||
return await getSignedUrl(this.client, getFileObject, { | ||
expiresIn: 3600, | ||
}); | ||
}; | ||
|
||
public getCloudFrontFileUrl = (fileName: string): string => { | ||
return `https://${this.cfDistributionId}.cloudfront.net/${fileName}`; | ||
}; | ||
} | ||
|
||
export { FileService }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import { config } from '../config/config.js'; | ||
import { CryptService } from './crypt/crypt.service.js'; | ||
import { TokenService } from './token/token.services.js'; | ||
import { FileService } from './file/file.service.js'; | ||
|
||
const cryptService = new CryptService(); | ||
const fileService = new FileService(config); | ||
|
||
const secretKey = config.ENV.TOKEN.SECRET_KEY; | ||
const expirationTime = config.ENV.TOKEN.EXPIRATION_TIME; | ||
const tokenService = new TokenService(secretKey, expirationTime); | ||
|
||
export { cryptService, tokenService }; | ||
export { cryptService, fileService, tokenService }; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
frontend/src/bundles/auth/components/sign-up-form/constants/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { type UserSignUpRequestDto } from '~/bundles/users/users.js'; | ||
|
||
const DEFAULT_SIGN_UP_PAYLOAD: UserSignUpRequestDto = { | ||
name: '', | ||
email: '', | ||
password: '', | ||
confirmPassword: '', | ||
}; | ||
|
||
export { DEFAULT_SIGN_UP_PAYLOAD }; |
69 changes: 58 additions & 11 deletions
69
frontend/src/bundles/auth/components/sign-up-form/sign-up-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,99 @@ | ||
import { UserValidationMessage } from 'shared/src/bundles/users/users.js'; | ||
|
||
import { | ||
Box, | ||
Button, | ||
FormProvider, | ||
Heading, | ||
Input, | ||
Link, | ||
VStack, | ||
} from '~/bundles/common/components/components.js'; | ||
import { useAppForm } from '~/bundles/common/hooks/hooks.js'; | ||
import { AppRoute, DataStatus } from '~/bundles/common/enums/enums.js'; | ||
import { | ||
useAppForm, | ||
useAppSelector, | ||
useMemo, | ||
} from '~/bundles/common/hooks/hooks.js'; | ||
import { | ||
type UserSignUpRequestDto, | ||
userSignUpValidationSchema, | ||
} from '~/bundles/users/users.js'; | ||
|
||
import { FormError, FormHeader, PasswordInput } from '../common/components.js'; | ||
import { DEFAULT_SIGN_UP_PAYLOAD } from './constants/constants.js'; | ||
|
||
type Properties = { | ||
onSubmit: (payload: UserSignUpRequestDto) => void; | ||
}; | ||
|
||
const SignUpForm: React.FC<Properties> = ({ onSubmit }) => { | ||
const { dataStatus } = useAppSelector(({ auth }) => ({ | ||
dataStatus: auth.dataStatus, | ||
})); | ||
const form = useAppForm<UserSignUpRequestDto>({ | ||
initialValues: DEFAULT_SIGN_UP_PAYLOAD, | ||
validationSchema: userSignUpValidationSchema, | ||
onSubmit, | ||
}); | ||
|
||
const { handleSubmit } = form; | ||
const { handleSubmit, errors, values } = form; | ||
|
||
const isEmpty = useMemo( | ||
() => Object.values(values).some((value) => value.trim().length === 0), | ||
[values], | ||
); | ||
|
||
return ( | ||
<FormProvider value={form}> | ||
<Box bg="brand.200" w={64} p={6} rounded="md"> | ||
<Heading as="h1">Sign Up</Heading> | ||
|
||
<Box w="55%" color="white"> | ||
<FormHeader | ||
headerText="Create an account" | ||
subheader={ | ||
<> | ||
Already registerd?{' '} | ||
<Link to={AppRoute.SIGN_IN} variant="secondary"> | ||
Log In | ||
</Link> | ||
</> | ||
} | ||
/> | ||
<form onSubmit={handleSubmit}> | ||
<VStack spacing={4} align="flex-start"> | ||
<Input | ||
type="text" | ||
label="Full Name" | ||
placeholder="Name" | ||
name="name" | ||
/> | ||
<Input | ||
type="email" | ||
label="Email" | ||
placeholder="Enter your email" | ||
placeholder="[email protected]" | ||
name="email" | ||
/> | ||
<Input | ||
type="password" | ||
<PasswordInput | ||
label="Password" | ||
placeholder="Enter your password" | ||
name="password" | ||
hasError={Boolean(errors.password)} | ||
/> | ||
<PasswordInput | ||
label="Repeat password" | ||
name="confirmPassword" | ||
hasError={Boolean(errors.confirmPassword)} | ||
/> | ||
<FormError | ||
isVisible={dataStatus === DataStatus.REJECTED} | ||
message={ | ||
UserValidationMessage.USER_IS_NOT_AVAILABLE | ||
} | ||
/> | ||
<Button | ||
type="submit" | ||
label="Sign up" | ||
size="lg" | ||
sx={{ mt: '16px' }} | ||
isDisabled={isEmpty} | ||
/> | ||
<Button type="submit" label="Sign up" /> | ||
</VStack> | ||
</form> | ||
</Box> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.