Skip to content

Commit

Permalink
Remove redis
Browse files Browse the repository at this point in the history
  • Loading branch information
rjshkhr committed Jan 17, 2023
1 parent 1c0f264 commit a17d64f
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 35 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"scripts": {
"start": "NODE_ENV=development webpack serve",
"start": "NODE_ENV=development NODE_OPTIONS=--openssl-legacy-provider webpack serve",
"build": "NODE_ENV=production webpack",
"build:dev": "NODE_ENV=development webpack",
"lint": "eslint './src/**/*.{js,jsx,json}'",
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"dotenv": "^10.0.0",
"express": "^4.17.1",
"helmet": "^4.6.0",
"ioredis": "^4.27.10",
"joi": "^17.4.2",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.0.8",
Expand Down
3 changes: 1 addition & 2 deletions server/controllers/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ const login = async (req, res, next) => {
}
}

const logout = async (req, res, next) => {
const logout = async (_req, res, next) => {
try {
await userService.removeRefreshToken(req.userId)
res.json({ message: 'user logged out' })
} catch (err) {
next(err)
Expand Down
8 changes: 0 additions & 8 deletions server/middlewares/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import jwt from 'jsonwebtoken'

import config from '../utils/config.js'
import HttpError from '../utils/http-error.js'
import redisClient from '../utils/connect-redis.js'

const verifyToken = async (req, _res, next) => {
const authorization = req.get('authorization')
Expand All @@ -29,13 +28,6 @@ const verifyRefreshToken = async (req, _res, next) => {

const { id } = jwt.verify(refreshToken, config.REFRESH_TOKEN_SECRET)
req.userId = id

const tokenInRedis = await redisClient.get(id)

if (!(tokenInRedis && tokenInRedis === refreshToken)) {
throw new HttpError(403, 'invalid token')
}

next()
} catch (err) {
next(err)
Expand Down
7 changes: 0 additions & 7 deletions server/services/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import jwt from 'jsonwebtoken'

import User from '../models/user.model.js'
import config from '../utils/config.js'
import redisClient from '../utils/connect-redis.js'

const getAllUsers = async () => await User.find()

Expand All @@ -30,14 +29,9 @@ const signToken = id => {
const signRefreshToken = async id => {
const options = { expiresIn: config.REFRESH_TOKEN_LIFE }
const refreshToken = jwt.sign({ id }, config.REFRESH_TOKEN_SECRET, options)
await redisClient.set(id, refreshToken, 'PX', config.REFRESH_TOKEN_LIFE)
return refreshToken
}

const removeRefreshToken = async id => {
await redisClient.del(id)
}

const deleteUser = async id => await User.findByIdAndDelete(id)

export default {
Expand All @@ -49,6 +43,5 @@ export default {
validatePassowrd,
signToken,
signRefreshToken,
removeRefreshToken,
deleteUser
}
2 changes: 0 additions & 2 deletions server/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const {
TOKEN_LIFE,
REFRESH_TOKEN_SECRET,
REFRESH_TOKEN_LIFE,
REDIS_URI,
TMDB_API_KEY
} = process.env

Expand All @@ -24,6 +23,5 @@ export default {
TOKEN_LIFE,
REFRESH_TOKEN_SECRET,
REFRESH_TOKEN_LIFE,
REDIS_URI,
TMDB_API_KEY
}
14 changes: 0 additions & 14 deletions server/utils/connect-redis.js

This file was deleted.

0 comments on commit a17d64f

Please sign in to comment.