Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Vercel Preview Deployment
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
push:
branches-ignore:
- main
jobs:
Deploy-Preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update actions/checkout to the latest version.

The current version (v2) is outdated. Update to v4 for improved security and performance.

-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- uses: actions/checkout@v2
- uses: actions/checkout@v4
🧰 Tools
🪛 actionlint (1.7.4)

13-13: the runner of "actions/checkout@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
20 changes: 10 additions & 10 deletions apps/core/app/auth/login/_components/form/loginForm.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client";

import { zodResolver } from "@hookform/resolvers/zod";
import { postLoginSchema } from "@repo/apis/core/accounts/login/post/post-login.schema";
import { PostLoginRequest } from "@repo/apis/core/accounts/login/post/post-login.types";
import { UsePostLogin } from "@repo/apis/core/accounts/login/post/use-post-login";
import { postLoginSchema } from "@repo/apis/core/accounts/users/login/post/post-login.schema";
import type { PostLoginRequest } from "@repo/apis/core/accounts/users/login/post/post-login.types";
import { usePostLogin } from "@repo/apis/core/accounts/users/login/post/use-post-login";
import { setAuthTokens } from "@repo/apis/utils/cookies";
import { Button } from "@repo/ui/components/button";
import { Input } from "@repo/ui/components/input";
Expand All @@ -17,8 +17,8 @@ const LoginForm = () => {
const form = useForm<PostLoginRequest>({
resolver: zodResolver(postLoginSchema.request),
defaultValues: {
password: "abcd@1234",
username: "admin",
password: "",
username: "",
},
});

Expand All @@ -28,19 +28,19 @@ const LoginForm = () => {
formState: { errors },
} = form;

const loginMutation = UsePostLogin({
const loginMutation = usePostLogin({
onSuccess: (res) => {
console.log(res);
toast.success("Logged in successfully");
setAuthTokens(res.data);
setAuthTokens(res.data.data.token);
Comment on lines +33 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Potential exposure of sensitive data in logs
Logging the entire response object (which may contain auth tokens) could risk leakage in logs. Consider removing or sanitizing console.log to avoid storing tokens in logs.

- console.log(res);
  toast.success("Logged in successfully");
- setAuthTokens(res.data.data.token);
+ // console.log(res); // Remove or sanitize sensitive data
  setAuthTokens(res.data.data.token);

Committable suggestion skipped: line range outside the PR's diff.

router.push("/");
},
onError: (res) => {
toast.error(res.response?.data.message || "Something went wrong");
console.log(res);
toast.error(res.response?.data.message ?? "Something went wrong");
},
});

console.log("ispendimng", loginMutation.isPending);

const handleSubmitForm = handleSubmit(() => {
const values = form.getValues();
loginMutation.mutate(values);
Expand Down
6 changes: 3 additions & 3 deletions apps/core/app/auth/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const LoginPage = () => {
<LoginForm />
{/* line */}
<div className="flex items-center w-full gap-3">
<div className="w-full h-[1px] bg-gray-700 rounded-full"></div>
<div className="w-full h-[1px] bg-gray-700 rounded-full" />
<p className="text-base font-medium">OR</p>
<div className="w-full h-[1px] bg-gray-700 rounded-full"></div>
<div className="w-full h-[1px] bg-gray-700 rounded-full" />
</div>
{/* login with google and linkedin */}
<div className="w-full flex flex-col items-center gap-3">
Expand All @@ -41,7 +41,7 @@ const LoginPage = () => {
</div>
{/* forgot password */}
<div className=" flex gap-2 pb-4 text-sm">
<p>Don’t have an account?</p>{" "}
<p>Don’t have an account?</p>
<Link href={"/auth/signup"} prefetch={false}>
<p className="underline cursor-pointer">Sign up</p>
</Link>
Expand Down
4 changes: 2 additions & 2 deletions apps/core/app/auth/signup/otp/_components/signup-otp-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp";
// import icons
import { zodResolver } from "@hookform/resolvers/zod";
import { postRegisterCompleteSchema } from "@repo/apis/core/accounts/register/complete/post/post-register-complete.schema";
import { PostRegisterCompleteRequest } from "@repo/apis/core/accounts/register/complete/post/post-register-complete.types";
import type { PostRegisterCompleteRequest } from "@repo/apis/core/accounts/register/complete/post/post-register-complete.types";
import { UsePostRegisterComplete } from "@repo/apis/core/accounts/register/complete/post/use-post-register-complete";
import { Countdown } from "@repo/ui/components/countdown";
import { useRouter } from "next/navigation";
Expand Down Expand Up @@ -46,7 +46,7 @@ export const SignupOtpForm = (props: SignupOtpFormProps) => {
const muutation = UsePostRegisterComplete({
onSuccess: (res) => {
toast.info(res.data.message);
router.push(`/auth/login`);
router.push("/auth/login");
},

onError: (err) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/core/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextRequest, NextResponse } from "next/server";
import { type NextRequest, NextResponse } from "next/server";
import { COOKIES } from "@repo/ui/constant/cookie";

export function middleware(request: NextRequest) {
Expand Down
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion packages/apis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"devDependencies": {
"@repo/eslint-config": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@types/js-cookie": "^3.0.6",
"@types/node": "^20",
"@types/react": "^18",
"autoprefixer": "^10.4.19",
Expand All @@ -31,7 +32,7 @@
"@tanstack/react-query-devtools": "^5.62.2",
"axios": "^1.7.7",
"axios-mock-adapter": "^2.0.0",
"js-cookie": "3.0.5",
"js-cookie": "^3.0.5",
"zod": "^3.23.8"
},
"exports": {
Expand Down
4 changes: 2 additions & 2 deletions packages/apis/src/instance/core-api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { COOKIES } from "@repo/ui/constant/cookie";
import { postRefreshToken } from "../services/core/accounts/refresh/post/post-refresh-token";
import axios, { AxiosError } from "axios";
import axios, { type AxiosError } from "axios";
import Cookie from "js-cookie";

let isRefreshing = false;
let failedQueue: any[] = [];

export const coreApi = axios.create({
baseURL: "http://37.152.182.32/", // You can set your base URL here
baseURL: "https://api.pixelgenius.design", // You can set your base URL here
headers: {
"Content-Type": "application/json",
},
Expand Down
2 changes: 1 addition & 1 deletion packages/apis/src/instance/guest-api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from "axios";

export const guestApi = axios.create({
baseURL: "http://37.152.182.32/", // You can set your base URL here
baseURL: "https://api.pixelgenius.design", // You can set your base URL here
headers: {
"Content-Type": "application/json",
},
Expand Down
27 changes: 27 additions & 0 deletions packages/apis/src/schema/api-response-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import z from "zod";

export const apiResponseSchema = z.object({
data: z.union([
z.array(z.any()),
z.record(z.string(), z.any()),
z.null(),
z.undefined(),
]),
message: z.union([z.string(), z.null(), z.undefined()]),
error: z.union([
z.record(z.string(), z.any()),
z.array(z.unknown()),
z.null(),
z.undefined(),
]),
meta: z.union([
z
.object({
page: z.number(),
per_page: z.number(),
})
.optional(),
z.null(),
z.undefined(),
]),
});
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { apiResponseSchema } from "#schema/api-response-schema";
import { z } from "zod";

export const postLoginRequestSchemaTransformed = z
.object({
username: z.string().min(3, "Username must be at least 3 characters long"),
password: z.string().min(8, "Password must be at least 8 characters long"),
otp: z.string().optional(),
})
.transform((data) => data);

export const postLoginResponseSchemaTransofrmed = z
.object({
refresh: z.string(),
access: z.string(),
export const postLoginResponseSchemaTransofrmed = apiResponseSchema
.extend({
data: z.object({
id: z.number(),
username: z.string(),
email: z.string(),
is_active: z.boolean(),
is_email_verified: z.boolean(),
token: z.object({
refresh: z.string(),
access: z.string(),
}),
}),
})
.transform((data) => data);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ApiResponse } from "@repo/apis/types/api.types";
import type { ApiResponse } from "@repo/apis/types/api.types";
import { requestHandler } from "@repo/apis/utils/request-handler";

import path from "path";
import { postLoginSchema as schema } from "./post-login.schema";
import {
import type {
PostLoginRequest,
PostLoginResponseTransformed,
} from "./post-login.types";
import { guestApi } from "#instance/guest-api";

export const postLoginURL = () => path.join("/accounts/login/");
export const postLoginURL = () => path.join("accounts/users/login/");

export const postLogin = async (
props?: PostLoginRequest,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { z } from "zod";
import { postLoginSchema } from "./post-login.schema";
import type { z } from "zod";
import type { postLoginSchema } from "./post-login.schema";

// Response
// Request
export type PostLoginRequest = z.input<typeof postLoginSchema.request>;

export type PostLoginRequestTransofrmed = z.infer<
typeof postLoginSchema.request
>;

// Request
// Response
export type PostLoginResponse = z.input<typeof postLoginSchema.response>;

export type PostLoginResponseTransformed = z.infer<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
import type {
ApiError,
ApiResponse,
UseMutationProps,
} from "@repo/apis/types/api.types";
import { useMutation } from "@tanstack/react-query";
import { postLogin } from "./post-login";
import {
import type {
PostLoginRequest,
PostLoginResponseTransformed,
} from "./post-login.types";
Expand All @@ -18,7 +18,7 @@ export type UsePostLoginProps = UseMutationProps<

export const postLoginQueryKey = () => ["postLogin"];

export const UsePostLogin = (props?: UsePostLoginProps) => {
export const usePostLogin = (props?: UsePostLoginProps) => {
const mutation = useMutation<
ApiResponse<PostLoginResponseTransformed>,
ApiError,
Expand Down
6 changes: 3 additions & 3 deletions packages/apis/src/types/api.types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { apiResponseSchema } from "#schema/api-response-schema.js";
import {
DefinedInitialDataOptions,
QueryKey,
UseMutationOptions,
} from "@tanstack/react-query";
import { AxiosError, AxiosResponse } from "axios";
import z from "zod";

export type ApiResponse<T = any, D = any> = AxiosResponse<T, D>;

Expand All @@ -25,6 +27,4 @@ export type UseMutationProps<
TContext = unknown,
> = Partial<UseMutationOptions<TData, TError, TVariables, TContext>>;

export type ApiError = AxiosError<{
message: string;
}>;
export type ApiError = AxiosError<z.input<typeof apiResponseSchema>>;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type Use{{pascalCase method}}{{pascalCase name}}Props = UseMutationProps<

export const {{method}}{{pascalCase name}}QueryKey = () => ["{{method}}{{pascalCase name}}"];

export const Use{{pascalCase method}}{{pascalCase name}} = (props?: Use{{pascalCase method}}{{pascalCase name}}Props) => {
export const use{{pascalCase method}}{{pascalCase name}} = (props?: Use{{pascalCase method}}{{pascalCase name}}Props) => {
const mutation = useMutation<
ApiResponse<{{pascalCase method}}{{pascalCase name}}ResponseTransformed>,
ApiError,
Expand Down
13 changes: 7 additions & 6 deletions packages/apis/turbo/generators/templates/schema.hbs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { apiResponseSchema } from "#schema/api-response-schema";
import { z } from "zod";

// Response
// Request
export const {{method}}{{pascalCase name}}RequestSchemaTransformed = z
.object({
keyPayload: z.string(),
})
.transform((data) => data);

// Request
export const {{method}}{{pascalCase name}}ResponseSchemaTransofrmed = z
.object({
// Response
export const {{method}}{{pascalCase name}}ResponseSchemaTransofrmed = apiResponseSchema.extend({
data: z.object({
keyBody: z.string(),
})
.transform((data) => data);
}),
}).transform((data) => data);;

export const {{method}}{{pascalCase name}}Schema = {
response: {{method}}{{pascalCase name}}ResponseSchemaTransofrmed,
Expand Down
Loading