System Information
- Strapi Version: 4.12.4
- Operating System: OS
- Database: SQLITE
- Node Version: >=16.0.0 <=20.x.x
- NPM Version: >=6.0.0
- Yarn Version:
I am fresh to strapi. I have developed a frontend management system and use the basic strapi authentication function. The jwt token expiry time is set as 5 minutes. Now I need to develop another management system and the jwt token expiry time is supposed to be 8h.
I tried to add a ‘src/extensions/custome-auth/config/routes.json’ and ‘src/extensions/custom-auth/controllers/CustomeAuth.js’ files.
for the ‘src/extensions/custome-auth/config/routes.json’
[
{
“method”: “POST”,
“path”: “/custom-login”,
“handler”: “custom-auth.login”,
“config”: {
“policies”:
}
}
]
for the ‘src/extensions/custom-auth/controllers/CustomeAuth.js’, I worte;
const jwt=require(‘jsonwebtoken’)
module.exports={
async login2(ctx){
const { username,password } = ctx.request.body;
try {
// This system only has one user
//the authenticating logic would be if the username and password are correct,
//. the user would get a token
if (username === 'admin' && password === 'sauvereign123') {
// 生成适用于第二个登录页面的 JWT
const token = jwt.sign({ username }, process.env.JWT_SECRET, { expiresIn: '30' });
// 返回 JWT
ctx.send({ token });
} else {
// 验证失败
ctx.throw(401, 'Invalid credentials');
}
} catch (error) {
ctx.throw(500, 'Internal server error');
}
}
}
Then I use postman to test. returned ‘method not allowed’, What can I do?