diff --git a/.env b/.env new file mode 100644 index 0000000..efab21d --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +NEXTAUTH_SECRET=";sadmfxflpdk" +NEXTAUTH_URL="http://localhost:3000" \ No newline at end of file diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts new file mode 100644 index 0000000..8db3ff8 --- /dev/null +++ b/app/api/auth/[...nextauth]/route.ts @@ -0,0 +1,91 @@ +import axios from "axios"; +import NextAuth, { NextAuthOptions } from "next-auth"; +import { JWT } from "next-auth/jwt"; +import CredentialsProvider from "next-auth/providers/credentials"; + +interface IToken { + access: string; +} + +const refreshToken = async (token: JWT): Promise => { + const data = { + refresh: token.refresh_token, + }; + + const response = await axios.post( + "https://api.kgroaduat.fishrungames.com/api/v1/token/refresh/", + data + ); + + return { + ...token, + access_token: response.data.access, + }; +}; + +export const authOptions: NextAuthOptions = { + providers: [ + CredentialsProvider({ + name: "Credentials", + credentials: { + email: { + label: "Email", + type: "text", + placeholder: "jsmith@example.com", + }, + password: { label: "Password", type: "password" }, + }, + async authorize(credentials, req) { + if (!credentials?.email || !credentials?.password) + return null; + const { email, password } = credentials as any; + + const res = await fetch( + "https://api.kgroaduat.fishrungames.com/api/v1/users/login/", + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + email, + password, + }), + } + ); + + if (res.status === 401) { + console.log(res.status); + return null; + } + + const user = await res.json(); + return user; + }, + }), + ], + pages: { + signIn: "/sign-in", + }, + session: { + strategy: "jwt", + }, + callbacks: { + async jwt({ token, user }) { + if (user) return { ...token, ...user }; + + return refreshToken(token); + }, + + async session({ token, session }) { + session.access_token = token.access_token; + session.refresh_token = token.refresh_token; + + return session; + }, + }, +}; + +const handler = NextAuth(authOptions); + +export { handler as GET, handler as POST }; diff --git a/app/create-report/page.tsx b/app/create-report/page.tsx new file mode 100644 index 0000000..e05f648 --- /dev/null +++ b/app/create-report/page.tsx @@ -0,0 +1,3 @@ +import CreateReportPage from "@/Pages/CreateReportPage/CreateReportPage"; + +export default CreateReportPage; diff --git a/app/profile/layout.tsx b/app/profile/layout.tsx new file mode 100644 index 0000000..7eb27f3 --- /dev/null +++ b/app/profile/layout.tsx @@ -0,0 +1,3 @@ +import ProfileLayout from "@/Pages/profile/ProfilePage/ProfileLayout"; + +export default ProfileLayout; diff --git a/app/profile/my-reports/page.tsx b/app/profile/my-reports/page.tsx new file mode 100644 index 0000000..3e91dd0 --- /dev/null +++ b/app/profile/my-reports/page.tsx @@ -0,0 +1,3 @@ +import MyReportsPage from "@/Pages/profile/MyReportsPage/MyReportsPage"; + +export default MyReportsPage; diff --git a/app/profile/page.tsx b/app/profile/page.tsx deleted file mode 100644 index a54c709..0000000 --- a/app/profile/page.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react"; - -const page = () => { - return
page
; -}; - -export default page; diff --git a/app/profile/personal-data/page.tsx b/app/profile/personal-data/page.tsx new file mode 100644 index 0000000..9122a75 --- /dev/null +++ b/app/profile/personal-data/page.tsx @@ -0,0 +1,3 @@ +import PersonalDataPage from "@/Pages/profile/PersonalDataPage/PersonalDataPage"; + +export default PersonalDataPage; diff --git a/app/report/[id]/page.tsx b/app/report/[id]/page.tsx new file mode 100644 index 0000000..614d113 --- /dev/null +++ b/app/report/[id]/page.tsx @@ -0,0 +1,3 @@ +import ReportDetailsPage from "@/Pages/ReportDetailsPage/ReportDetailsPage"; + +export default ReportDetailsPage; diff --git a/lib/next-auth.d.ts b/lib/next-auth.d.ts new file mode 100644 index 0000000..f526420 --- /dev/null +++ b/lib/next-auth.d.ts @@ -0,0 +1,18 @@ +import NextAuth from "next-auth"; + +declare module "next-auth" { + interface Session { + refresh_token: string; + access_token: string; + } +} + +import { JWT } from "next-auth/jwt"; + +declare module "next-auth/jwt" { + interface JWT { + refresh_token: string; + access_token: string; + exp: number; + } +} diff --git a/package.json b/package.json index c6f06bb..774b7ae 100644 --- a/package.json +++ b/package.json @@ -10,17 +10,22 @@ }, "dependencies": { "axios": "^1.6.5", + "leaflet": "^1.9.4", "next": "14.1.0", + "next-auth": "^4.24.5", "react": "^18", "react-dom": "^18", + "react-leaflet": "^4.2.1", "sass": "^1.70.0", - "swr": "^2.2.4", + "use-debounce": "^10.0.0", "zustand": "^4.5.0" }, "devDependencies": { + "@types/leaflet": "^1.9.8", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", + "@types/react-leaflet": "^3.0.0", "eslint": "^8", "eslint-config-next": "14.1.0", "typescript": "^5" diff --git a/src/App/App.tsx b/src/App/App.tsx index fd75142..18826aa 100644 --- a/src/App/App.tsx +++ b/src/App/App.tsx @@ -2,6 +2,7 @@ import { Montserrat } from "next/font/google"; import "./globals.scss"; import Navbar from "@/Widgets/general/Navbar/Navbar"; import Footer from "@/Widgets/general/Footer/Footer"; +import { Providers } from "./Providers"; const montserrat = Montserrat({ subsets: ["latin"] }); @@ -13,9 +14,11 @@ export default function RootLayout({ return ( - - {children} -