-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
relates #28
- Loading branch information
Showing
17 changed files
with
153 additions
and
55 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
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 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,18 @@ | ||
import React from "react"; | ||
import axios from "axios"; | ||
|
||
function Signout() { | ||
const signout = () => { | ||
axios | ||
.get("/signout") | ||
.then((data) => (window.location.href = "/")) | ||
.catch((err) => console.log(err)); | ||
}; | ||
return ( | ||
<button onClick={signout} type="submit" className="nav-item btn"> | ||
Sign out | ||
</button> | ||
); | ||
} | ||
|
||
export default Signout; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
const signup = require("./signup"); | ||
const signin = require("./signin"); | ||
const signout = require("./signout"); | ||
|
||
module.exports = { | ||
signin, | ||
signup, | ||
signout, | ||
}; |
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,5 @@ | ||
const signout = (req, res, next) => { | ||
res.clearCookie("jwt").send("Signed Out"); | ||
}; | ||
|
||
module.exports = signout; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
const userRouter = require("express").Router(); | ||
const { signup } = require("../controllers/user"); | ||
const { signin } = require("../controllers/user"); | ||
const { signout } = require("../controllers/user"); | ||
const authUser = require("../utils/authUser"); | ||
|
||
userRouter.post("/api/v1/users/signup", signup); | ||
userRouter.post("/api/v1/users/signin", signin); | ||
|
||
userRouter.get("/isLogged", authUser); | ||
userRouter.get("/signout", signout); | ||
module.exports = userRouter; |
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,20 @@ | ||
/* eslint-disable no-multi-assign */ | ||
const { verify } = require("jsonwebtoken"); | ||
const CustomError = require("./CustomError"); | ||
require("env2")(".env"); | ||
|
||
module.exports = authUser = (req, res, next) => { | ||
try { | ||
const existedToken = req.cookies.jwt; | ||
if (!existedToken) throw new CustomError("You are not authorized!", 400); | ||
verify(existedToken, process.env.SECRET_KEY, (err, decoded) => { | ||
if (err) { | ||
throw new CustomError("Token is being manipulated!", 400); | ||
} else { | ||
res.send(decoded); | ||
} | ||
}); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}; |
Oops, something went wrong.