feat(authorization): e2e working authorization
This commit is contained in:
@@ -19,12 +19,24 @@ type BaseRequestParams = Partial<{
|
||||
|
||||
const getBaseRequest = ({ path, body, method }: BaseRequestParams): Request => {
|
||||
return new Request(`http://localhost:3040/${path}`, {
|
||||
headers: { userId: "1db09f34-b155-4bf2-b606-dda25365fc89" },
|
||||
body,
|
||||
method,
|
||||
});
|
||||
};
|
||||
|
||||
const getBaseAuthorizedRequest = ({
|
||||
path,
|
||||
body,
|
||||
method,
|
||||
}: BaseRequestParams): Request => {
|
||||
return new Request(`http://localhost:3040/${path}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${localStorage.getItem("access")?.toString()}`,
|
||||
},
|
||||
body,
|
||||
method,
|
||||
});
|
||||
};
|
||||
const sendImageResponseValidator = strictObject({
|
||||
ID: pipe(string(), uuid()),
|
||||
ImageID: pipe(string(), uuid()),
|
||||
@@ -35,7 +47,7 @@ export const sendImage = async (
|
||||
imageName: string,
|
||||
base64Image: string,
|
||||
): Promise<InferOutput<typeof sendImageResponseValidator>> => {
|
||||
const request = getBaseRequest({
|
||||
const request = getBaseAuthorizedRequest({
|
||||
path: `image/${imageName}`,
|
||||
body: base64Image,
|
||||
method: "POST",
|
||||
@@ -107,7 +119,7 @@ const getUserImagesResponseValidator = array(dataTypeValidator);
|
||||
export type UserImage = InferOutput<typeof dataTypeValidator>;
|
||||
|
||||
export const getUserImages = async (): Promise<UserImage[]> => {
|
||||
const request = getBaseRequest({ path: "image" });
|
||||
const request = getBaseAuthorizedRequest({ path: "image" });
|
||||
|
||||
const res = await fetch(request).then((res) => res.json());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user