Skip to content

Commit 97287f8

Browse files
committed
Minor Changes
1 parent c68ba5e commit 97287f8

4 files changed

Lines changed: 15 additions & 75 deletions

File tree

client/.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
REACT_EDITOR=code
22

33
APP_ENV=DEVELOPMENT
4-
NEXT_PUBLIC_BACKEND_URL="http://localhost:8000/api"
4+
# NEXT_PUBLIC_BACKEND_URL="http://localhost:8000/api"
5+
NEXT_PUBLIC_BACKEND_URL="http://127.0.0.1:8000"

client/src/context/AuthContext.tsx

Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,3 @@
1-
// import { createContext, useContext, useEffect, useState } from "react";
2-
// import api from "../lib/api";
3-
// import { useRouter } from "next/router";
4-
5-
// const AuthContext = createContext<any>(null);
6-
7-
// export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
8-
// const [user, setUser] = useState<any>(null);
9-
// const [loading, setLoading] = useState(true);
10-
// const router = useRouter();
11-
12-
// const loadUser = async () => {
13-
// const token = localStorage.getItem("access");
14-
// if (!token) {
15-
// setLoading(false);
16-
// return;
17-
// }
18-
19-
// try {
20-
// const res = await api.get("/user/me/");
21-
// // const res = await api.get("/api/user/me/");
22-
// // const res = await api.get("/user/me/");
23-
// setUser(res.data);
24-
// } catch (err) {
25-
// console.error("Failed to fetch user", err);
26-
// logout();
27-
// // setUser(null);
28-
// } finally {
29-
// setLoading(false);
30-
// }
31-
// // const res = await api.get("/user/me/");
32-
// // const res = await api.get("http://127.0.0.1:8000/api/user/me/");
33-
// // http://127.0.0.1:8000/api/token/refresh/
34-
// // const res = await api.get("/user_profile/me/");
35-
// };
36-
// const login = async (username: string, password: string) => {
37-
// // const res = await api.post("/api/token/", { username, password });
38-
// const res = await api.post("/token/", { username, password });
39-
// localStorage.setItem("access", res.data.access);
40-
// localStorage.setItem("refresh", res.data.refresh);
41-
// await loadUser(); // Fetch user data immediately after getting token
42-
// router.push("/user_dashboard/"); // Redirect to dashboard
43-
// };
44-
45-
// const logout = () => {
46-
// localStorage.removeItem("access");
47-
// localStorage.removeItem("refresh");
48-
// setUser(null);
49-
// // router.push("/login");
50-
// router.push("/user_login");
51-
// router.push("/user_login");
52-
// };
53-
54-
// useEffect(() => {
55-
// loadUser();
56-
// }, []);
57-
58-
// return (
59-
// <AuthContext.Provider value={{ user, setUser, loading, login, logout }}>
60-
// {children}
61-
// </AuthContext.Provider>
62-
// );
63-
// };
64-
65-
// export const useAuth = () => useContext(AuthContext);
661
import { useRouter } from "next/router";
672
import {
683
createContext,
@@ -125,7 +60,8 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
12560
localStorage.setItem("access", res.data.access);
12661
localStorage.setItem("refresh", res.data.refresh);
12762
await loadUser();
128-
router.push("/user_dashboard/");
63+
router.push("/user_dashboard");
64+
// router.push("/user_dashboard/");
12965
};
13066

13167
useEffect(() => {

client/src/lib/api.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ api.interceptors.response.use(
2626
if (refreshToken) {
2727
try {
2828
// Attempt to get a new access token
29-
const res = await axios.post(
30-
`${process.env.NEXT_PUBLIC_BACKEND_URL}/token/refresh/`,
31-
{
32-
refresh: refreshToken,
33-
},
34-
);
29+
// const res = await axios.post(
30+
// `${process.env.NEXT_PUBLIC_BACKEND_URL}/token/refresh/`,
31+
// {
32+
// refresh: refreshToken,
33+
// },
34+
// );
35+
const res = await api.post("/token/refresh/", {
36+
refresh: refreshToken,
37+
});
3538

3639
if (res.status === 200) {
3740
localStorage.setItem("access", res.data.access);

server/server/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@
6868
CORS_ALLOWED_ORIGINS: list[str] = []
6969
if DEBUG:
7070
# CORS_ALLOWED_ORIGINS.extend(["http://localhost:3000", "http://127.0.0.1:3000", "http://127.0.0.1:8000", "http://192.168.0.157:3000/"])
71-
CORS_ALLOWED_ORIGINS.extend(["http://localhost:3000", "http://127.0.0.1:3000", "http://127.0.0.1:8000", "http://192.168.0.157:3000"])
71+
CORS_ALLOWED_ORIGINS.extend(["http://localhost:3000", "http://127.0.0.1:3000", "http://127.0.0.1:8000", "http://192.168.0.157:3000", "http://192.168.1.247:3000"])
7272
if FRONTEND_URL:
7373
# CORS_ALLOWED_ORIGINS.append(FRONTEND_URL, "http://192.168.0.157:3000/")
74-
CORS_ALLOWED_ORIGINS.extend(FRONTEND_URL, "http://192.168.0.157:3000/", "http://localhost:3000", "http://127.0.0.1:3000", "http://127.0.0.1:8000" )
74+
CORS_ALLOWED_ORIGINS.extend(FRONTEND_URL, "http://192.168.0.157:3000/", "http://localhost:3000", "http://127.0.0.1:3000", "http://127.0.0.1:8000", "http://192.168.1.247:3000" )
7575

7676
# Testing
7777
CORS_ALLOW_HEADERS = [

0 commit comments

Comments
 (0)