Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
feat: added new middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
Sreesanjay committed Mar 10, 2024
1 parent 411bf3f commit 62b0223
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
14 changes: 2 additions & 12 deletions client/src/features/authSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ const authSlice = createSlice({
state.isSuccess = true;
state.user = action.payload.user;
localStorage.setItem("user", JSON.stringify(action.payload.user));
Cookies.set("token", action.payload.token, {
secure: true,
sameSite: "none",
path: '/',
expires: 3,
});
Cookies.set("token", action.payload.token, { expires: 3, sameSite: 'none', secure: true });
})
.addCase(login.rejected, (state, action) => {
state.isLoading = false;
Expand All @@ -57,12 +52,7 @@ const authSlice = createSlice({
state.isSuccess = true;
state.user = action.payload.user;
localStorage.setItem("user", JSON.stringify(action.payload.user));
Cookies.set("token", action.payload.token, {
secure: true,
sameSite: "none",
path: '/',
expires: 3,
});
Cookies.set("token", action.payload.token, { expires: 3, sameSite: 'none', secure: true });
})
.addCase(signUp.rejected, (state, action) => {
state.isLoading = false;
Expand Down
10 changes: 8 additions & 2 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const { notFound, errorHandler } = require('./middlewares/errorMiddlewares')

const userRoute = require('./routes/indexRoute.js')
const adminRoute = require('./routes/adminRoute.js')
// const ORIGIN = process.env.NODE_ENV === 'development' ? "http://localhost:4000" : 'https://thalia.vercel.app'
const ORIGIN = ["http://localhost:4000", 'https://thalia.vercel.app']
const ORIGIN = process.env.NODE_ENV === 'development' ? "http://localhost:4000" : 'https://thalia.vercel.app'
const corsConfig = {
origin: ORIGIN,
credentials: true,
Expand All @@ -25,6 +24,13 @@ app.use(express.json());
app.use(express.urlencoded({ extended: true }))
app.use(cookieParser());
app.use(cors(corsConfig))
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', ORIGIN);
res.setHeader('Access-Control-Allow-Credentials', true);
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Authorization, Content-Type');
next();
});

//routes
app.use('/api', userRoute)
Expand Down

0 comments on commit 62b0223

Please sign in to comment.