Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ And that's it! Your `SkateHub Frontend` should now be up and running locally on

### 2024

- 2024-12-19 - Implement server-side redirection for authenticated users [#103](https://github.com/jpcmf/Frontend-GraduateProgram-FullStack-2024/pull/103) _(v0.1.30)_
- 2024-12-12 - Update user avatar handling and modify user data structure [#99](https://github.com/jpcmf/Frontend-GraduateProgram-FullStack-2024/pull/99) _(v0.1.29)_
- 2024-12-07 - Add custom `404 error` page [#91](https://github.com/jpcmf/Frontend-GraduateProgram-FullStack-2024/pull/91) _(v0.1.28)_
- 2024-12-07 - Implement user profile update functionality in AuthContext [#89](https://github.com/jpcmf/Frontend-GraduateProgram-FullStack-2024/pull/89) _(v0.1.27)_
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "skatehub-frontend",
"version": "0.1.29",
"version": "0.1.30",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
5 changes: 5 additions & 0 deletions src/pages/auth/forgot-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Box, Button, Divider, Flex, Stack, Text } from "@chakra-ui/react";
import { API } from "@/utils/constant";
import { Toast } from "@/components/Toast";
import { Input } from "@/shared/components/Form/Input";
import { redirectIfAuthenticated } from "@/utils/auth";

const forgotPasswordFormSchema = z.object({
email: z.string().email("E-mail inválido.").nonempty("Campo obrigatório.")
Expand Down Expand Up @@ -155,3 +156,7 @@ export default function ForgotPassword() {
</>
);
}

export const getServerSideProps = async (ctx: any) => {
return redirectIfAuthenticated(ctx);
};
5 changes: 5 additions & 0 deletions src/pages/auth/reset-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Button, Divider, Flex, Stack, Text } from "@chakra-ui/react";
import { API } from "@/utils/constant";
import { Toast } from "@/components/Toast";
import { Input } from "@/shared/components/Form/Input";
import { redirectIfAuthenticated } from "@/utils/auth";

const resetPasswordFormSchema = z
.object({
Expand Down Expand Up @@ -157,3 +158,7 @@ export default function ResetPassword() {
</>
);
}

export const getServerSideProps = async (ctx: any) => {
return redirectIfAuthenticated(ctx);
};
5 changes: 5 additions & 0 deletions src/pages/auth/signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Input } from "@/shared/components/Form/Input";
import { Toast } from "@/components/Toast";
import { AuthContext } from "@/contexts/AuthContext";
import { LogoSkateHub } from "@/components/LogoSkateHub";
import { redirectIfAuthenticated } from "@/utils/auth";

const signInFormSchema = z.object({
email: z.string().email({ message: "E-mail deve ser um e-mail válido." }).min(1, { message: "Campo obrigatório." }),
Expand Down Expand Up @@ -184,3 +185,7 @@ export default function SignIn() {
</>
);
}

export const getServerSideProps = async (ctx: any) => {
return redirectIfAuthenticated(ctx);
};
5 changes: 5 additions & 0 deletions src/pages/auth/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Button, Flex, Text, Stack, Box, Divider } from "@chakra-ui/react";
import { API } from "@/utils/constant";
import { Input } from "@/shared/components/Form/Input";
import { Toast } from "@/components/Toast";
import { redirectIfAuthenticated } from "@/utils/auth";

const signUpSchema = z
.object({
Expand Down Expand Up @@ -248,3 +249,7 @@ export default function SignUp() {
</>
);
}

export const getServerSideProps = async (ctx: any) => {
return redirectIfAuthenticated(ctx);
};
7 changes: 7 additions & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { Button, Flex, Grid, GridItem, Stack, Text } from "@chakra-ui/react";

import packageJson from "../../package.json";
import { LogoSkateHub } from "@/components/LogoSkateHub";
// import { useEffect } from "react";
// import { destroyCookie, parseCookies } from "nookies";
import { redirectIfAuthenticated } from "@/utils/auth";

export default function Home() {
const router = useRouter();
Expand Down Expand Up @@ -112,3 +115,7 @@ export default function Home() {
</>
);
}

export const getServerSideProps = async (ctx: any) => {
return redirectIfAuthenticated(ctx);
};
19 changes: 19 additions & 0 deletions src/utils/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { GetServerSidePropsContext } from "next";
import { parseCookies } from "nookies";

export const redirectIfAuthenticated = (ctx: GetServerSidePropsContext) => {
const { ["auth.token"]: token } = parseCookies(ctx);

if (token) {
return {
redirect: {
destination: "/dashboard",
permanent: false
}
};
}

return {
props: {}
};
};
Loading