Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-mini-2024-07-18· OpenAIAi2 WildChat-4.8M (AI2)

Description: create jwt token verifications functions as a middleware functions, both…

  1. User

    Description: create jwt token verifications functions as a middleware functions, both access token and refresh token

    		  Generate source code based on the description above and respond in the following JSON format ONLY:
    			```json
    				{
    				"name": "prompt_name",
    				"schema": {
    					"type": "string",
    					"code": "Generated code here"
    				}
    				}
    				```
    		  
    		  IMPORTANT:
    		  - Ensure the JSON response is error-free.
    		  - Include no additional text or explanations. Respond with the JSON object only.
    
  2. Assistant
    {
      "name": "jwt_token_verification_middleware",
      "schema": {
        "type": "string",
        "code": "const jwt = require('jsonwebtoken');\n\nconst accessTokenSecret = 'your_access_token_secret';\nconst refreshTokenSecret = 'your_refresh_token_secret';\n\n// Middleware to verify access token\nconst verifyAccessToken = (req, res, next) => {\n    const token = req.headers['authorization']?.split(' ')[1];\n    if (!token) return res.sendStatus(403);\n\n    jwt.verify(token, accessTokenSecret, (err, user) => {\n        if (err) return res.sendStatus(403);\n        req.user = user;\n        next();\n    });\n};\n\n// Middleware to verify refresh token\nconst verifyRefreshToken = (req, res, next) => {\n    const token = req.body.refreshToken;\n    if (!token) return res.sendStatus(403);\n\n    jwt.verify(token, refreshTokenSecret, (err, user) => {\n        if (err) return res.sendStatus(403);\n        req.user = user;\n        next();\n    });\n};\n\nmodule.exports = { verifyAccessToken, verifyRefreshToken };"
      }
    }