This repository has been archived by the owner on Nov 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
69 changed files
with
3,440 additions
and
546 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,9 @@ SENTRY_DSN=https://[email protected]/544 | |
JWT_SECRET= | ||
|
||
DB_URL=postgresql://postgres:postgres@meetup-db/meetup | ||
|
||
MAILSERVER_ADDRESS= | ||
MAILSERVER_PORT= | ||
MAILSERVER_USERNAME= | ||
MAILSERVER_PASSWORD= | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import jwt from "jsonwebtoken"; | ||
import { | ||
HttpStatus, | ||
} from "../../helpers/http"; | ||
import { | ||
ApiError, | ||
Router, | ||
} from "../../helpers/route"; | ||
import { | ||
getJwtSecret, | ||
} from "../../helpers/token"; | ||
import AuthService from "../../services/auth-service"; | ||
import UserLogService from "../../services/user-log-service"; | ||
|
||
const router = new Router(); | ||
|
||
router.post("/", async ({ body, ip, ips }, res) => { | ||
const { email, password } = body; | ||
|
||
if (!email || !password) { | ||
throw new ApiError("no-credentials-provided"); | ||
} | ||
|
||
const user = await AuthService.login(email, password); | ||
|
||
if (!user) { | ||
throw new ApiError( | ||
"invalid-credentials", | ||
HttpStatus.Error.Client.Unauthorized, | ||
null, | ||
); | ||
} | ||
|
||
const { uid } = user; | ||
|
||
const payload = { | ||
uid, | ||
}; | ||
|
||
const token = jwt.sign( | ||
payload, | ||
getJwtSecret(), | ||
{ | ||
expiresIn: "2 weeks", | ||
}, | ||
); | ||
|
||
res.cookie( | ||
process.env.JOBFAIR_COOKIE_NAME, | ||
JSON.stringify({ | ||
token, | ||
}), | ||
{ | ||
domain: `.${ new URL(process.env.BASE_URL || "").hostname }`, | ||
expires: "", | ||
secure: "development" !== process.env.NODE_ENV, | ||
sameSite: "strict", | ||
}, | ||
); | ||
|
||
await UserLogService.log( | ||
user.uid, | ||
"login", | ||
{ | ||
ip, | ||
ips, | ||
}, | ||
); | ||
|
||
return user; | ||
}); | ||
|
||
export default router; |
Oops, something went wrong.