Skip to content

Commit

Permalink
--update: allowed origins and delete todos on user delete
Browse files Browse the repository at this point in the history
  • Loading branch information
ritiksr25 committed Apr 26, 2021
1 parent b156e9f commit 2b53c9a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 4 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ module.exports = () => {
// Allowing headers
app.use((req, res, next) => {
let origin = req.headers.origin;
if (ALLOWED_ORIGINS.includes(origin) || ALLOWED_ORIGINS[1].test(origin))
if (
ALLOWED_ORIGINS.includes(origin) ||
(ALLOWED_ORIGINS[2] && ALLOWED_ORIGINS[2].test(origin))
)
res.header("Access-Control-Allow-Origin", origin);
res.header(
"Access-Control-Allow-Headers",
Expand Down
14 changes: 8 additions & 6 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ module.exports = {
AVATAR_URL: process.env.AVATAR_URL,
GET_BIRTHDAYS_PROCESS_SECRET: process.env.GET_BIRTHDAYS_PROCESS_SECRET,
SENTRY_DSN: process.env.SENTRY_DSN,
ALLOWED_ORIGINS: [
"https://portal.dsckiet.com",
"http://localhost:3000",
"https://dsckiet-admin.netlify.app",
/[^.\s]+deploy\-preview\-([\d]{1,})--dsckiet-admin\.netlify\.app/
]
ALLOWED_ORIGINS:
process.env.NODE_ENV === "production"
? ["https://portal.dsckiet.com"]
: [
"http://localhost:3000",
"https://dsckiet-admin.netlify.app",
/[^.\s]+deploy\-preview\-([\d]{1,})--dsckiet-admin\.netlify\.app/
]
};
1 change: 1 addition & 0 deletions controllers/users_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ module.exports.deleteUser = async (req, res) => {
let key = `${user.image.split("/")[3]}/${user.image.split("/")[4]}`;
await deleteImage(key);
}
await Todo.deleteMany({ uid });
setToken(uid, "delete");
return sendSuccess(res, null);
};
Expand Down

0 comments on commit 2b53c9a

Please sign in to comment.