Skip to content

Commit

Permalink
Merge branch 'refs/heads/backend'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jul 5, 2024
2 parents 83118eb + bf40a9d commit 4789d9b
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 7 deletions.
6 changes: 5 additions & 1 deletion backend/dist/controllers/googleOAuth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ class Controller extends rootController_1.default {
this.login = this.catchAsync((req, res) => __awaiter(this, void 0, void 0, function* () {
if (req === null || req === void 0 ? void 0 : req.user) {
const result = yield googleOAuth_service_1.GoogleOAuthService.login(req.user);
res.cookie("tmAccessToken", result, { httpOnly: true, secure: true });
res.cookie("tmAccessToken", result, {
httpOnly: true,
sameSite: "lax",
secure: true,
});
res.redirect(envConfig_1.config.google.redirectUrl);
}
}));
Expand Down
6 changes: 5 additions & 1 deletion backend/dist/controllers/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ class Controller extends rootController_1.default {
this.login = this.catchAsync((req, res) => __awaiter(this, void 0, void 0, function* () {
const { email, password } = req.body;
const result = yield user_service_1.UserService.login(email, password);
res.cookie("tmAccessToken", result, { httpOnly: true, secure: true });
res.cookie("tmAccessToken", result, {
httpOnly: true,
sameSite: "lax",
secure: true,
});
this.apiResponse(res, {
statusCode: http_status_1.default.OK,
success: true,
Expand Down
2 changes: 2 additions & 0 deletions backend/dist/middlewares/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const http_status_1 = __importDefault(require("http-status"));
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
const verifyJwt = (req, res, next) => {
try {
console.log({ Cookies: req.cookies });
console.log({ Token: req.cookies.tmAccessToken });
const token = req.cookies.tmAccessToken;
if (!token) {
return res.json({
Expand Down
6 changes: 5 additions & 1 deletion backend/src/controllers/googleOAuth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ class Controller extends RootController {
login = this.catchAsync(async (req: Request, res: Response) => {
if (req?.user) {
const result: string = await GoogleOAuthService.login(req.user);
res.cookie("tmAccessToken", result, { httpOnly: true, secure: true });
res.cookie("tmAccessToken", result, {
httpOnly: true,
sameSite: "lax",
secure: true,
});
res.redirect(config.google.redirectUrl);
}
});
Expand Down
6 changes: 5 additions & 1 deletion backend/src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ class Controller extends RootController {
login = this.catchAsync(async (req: Request, res: Response) => {
const { email, password } = req.body;
const result = await UserService.login(email, password);
res.cookie("tmAccessToken", result, { httpOnly: true, secure: true });
res.cookie("tmAccessToken", result, {
httpOnly: true,
sameSite: "lax",
secure: true,
});
this.apiResponse(res, {
statusCode: httpStatus.OK,
success: true,
Expand Down
2 changes: 2 additions & 0 deletions backend/src/middlewares/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import jwt from "jsonwebtoken";

const verifyJwt = (req: Request, res: Response, next: NextFunction) => {
try {
console.log({ Cookies: req.cookies });
console.log({ Token: req.cookies.tmAccessToken });
const token = req.cookies.tmAccessToken;
if (!token) {
return res.json({
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/shared/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Navbar = () => {
const { theme, setTheme } = useTheme();
const { data }: any = useLoggedInUserQuery({});
const user: IUser = data?.data;
console.log("User from navbar", user);
const [isOpen, setIsOpen] = useState(false);
const [toggle, setToggle] = useState(false);
const { data: notifiedData } = useGetNotificationQuery(user?.id);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/features/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const userApi = apiSlice.injectEndpoints({
loginUser: builder.mutation({
query: (data) => ({
method: "POST",
url: "https://api-team-manager.onrender.com/user/login",
url: "/user/login",
body: data,
credentials: "include",
}),
Expand All @@ -26,7 +26,7 @@ const userApi = apiSlice.injectEndpoints({
}),
loggedInUser: builder.query({
query: () => ({
url: "https://api-team-manager.onrender.com/user/auth",
url: "/user/auth",
credentials: "include",
}),
providesTags: ["user"] as any,
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/hooks/useGetLoggedInUser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect, useState } from "react";
import Cookies from "js-cookie";
import { IUser, userInitData } from "@/interfaces/user.interface";

const useGetLoggedInUser = () => {
Expand All @@ -15,10 +14,12 @@ const useGetLoggedInUser = () => {
}
);
const data = await res.json();
console.log("User from useGetLoggedInUser hook", data);
setUser(data?.data);
} catch (error) {
console.log("Failed to fetch user");
}
console.log("Will call");
};
fetchUser();
}, []);
Expand Down

0 comments on commit 4789d9b

Please sign in to comment.