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 acd858e + 10938c0 commit 7321446
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 28 deletions.
1 change: 1 addition & 0 deletions backend/dist/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ app.use((0, cors_1.default)({
credentials: true,
}));
app.use(express_1.default.json());
app.use(express_1.default.urlencoded({ extended: true }));
app.use((0, cookie_parser_1.default)());
app.use((0, helmet_1.default)());
app.use((0, express_session_1.default)({
Expand Down
1 change: 1 addition & 0 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ app.use(
})
);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(helmet());
app.use(
Expand Down
1 change: 1 addition & 0 deletions backend/src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { config } from "@/configurations/envConfig";
import { UserService } from "@/services/user.service";
import RootController from "@/shared/rootController";
import { Request, Response } from "express";
Expand Down
1 change: 0 additions & 1 deletion backend/src/middlewares/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import jwt from "jsonwebtoken";
const verifyJwt = (req: Request, res: Response, next: NextFunction) => {
try {
const token = req.cookies.tmAccessToken;

if (!token) {
return res.json({
statusCode: httpStatus.BAD_REQUEST,
Expand Down
11 changes: 5 additions & 6 deletions frontend/src/components/pages/login/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable @next/next/no-img-element */
import { SubmitHandler, useForm } from "react-hook-form";
import Swal from "sweetalert2";
import Cookies from "js-cookie";
import { useLoginUserMutation } from "@/features/user";
import Link from "next/link";
import GoogleLogin from "@/components/shared/GoogleLogin";
import { IoMdEye, IoMdEyeOff } from "react-icons/io";
import { useState } from "react";
import { useRouter } from "next/router";

type FormData = {
email: string;
Expand All @@ -20,23 +20,22 @@ const Login = () => {
formState: { errors },
} = useForm<FormData>({ mode: "onChange" });
const [togglePassword, setTogglePassword] = useState(false);
const router = useRouter();

const [loginUser] = useLoginUserMutation();

const onSubmit: SubmitHandler<FormData> = async (data) => {
const result: any = await loginUser(data);
if (result?.data?.success) {
// Cookies.set("tmAccessToken", result?.data?.data, { expires: 6 });
if (result?.data?.statusCode === 200) {
Swal.fire({
position: "center",
icon: "success",
title: result?.data?.message,
showConfirmButton: false,
timer: 1500,
});
window.location.replace("/dashboard");
}
if (!result?.error?.data?.success) {
router.push("/dashboard");
} else {
Swal.fire({
position: "center",
icon: "error",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/shared/GoogleLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";

const GoogleLogin = () => {
const handleGoogleLogin = async () => {
window.open("https://api-team-manager.onrender.com/google/login", "_self");
window.open("http://api-team-manager.onrender.com/google/login", "_self");
};
return (
<div className="my-3 text-center font-semibold">
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/features/api/apiSlice.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
import Cookies from "js-cookie";

const apiSlice = createApi({
reducerPath: "api",
baseQuery: fetchBaseQuery({
baseUrl: "https://api-team-manager.onrender.com",
headers: {
"Content-type": "application/json",
authorization: Cookies.get("tmAccessToken") as string,
},
credentials: "include",
}),
tagTypes: [
"user",
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/features/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ const userApi = apiSlice.injectEndpoints({
loginUser: builder.mutation({
query: (data) => ({
method: "POST",
url: "/user/login",
url: "https://api-team-manager.onrender.com/user/login",
body: data,
credentials: "include",
}),
invalidatesTags: ["user"] as any,
}),
Expand All @@ -25,7 +26,8 @@ const userApi = apiSlice.injectEndpoints({
}),
loggedInUser: builder.query({
query: () => ({
url: "/user/auth",
url: "https://api-team-manager.onrender.com/user/auth",
credentials: "include",
}),
providesTags: ["user"] as any,
}),
Expand Down
22 changes: 9 additions & 13 deletions frontend/src/hooks/useGetLoggedInUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ const useGetLoggedInUser = () => {
useEffect(() => {
const fetchUser = async () => {
try {
const token = Cookies.get("tmAccessToken") as string;
if (token !== "undefined") {
const res = await fetch(
"https://api-team-manager.onrender.com/user/auth",
{
headers: {
authorization: token,
},
}
);
const data = await res.json();
setUser(data?.data);
}
const res = await fetch(
"https://api-team-manager.onrender.com/user/auth",
{
method: "GET",
credentials: "include",
}
);
const data = await res.json();
setUser(data?.data);
} catch (error) {
console.log("Failed to fetch user");
}
Expand Down

0 comments on commit 7321446

Please sign in to comment.