mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-07-09 22:42:19 +08:00
feature: auto refresh user token when token exp in 7 days (#644)
This commit is contained in:
@@ -116,7 +116,7 @@ export default {
|
||||
user_email: email,
|
||||
user_id: user_id,
|
||||
// 90 days expire in seconds
|
||||
exp: Math.floor(Date.now() / 1000) + 90 * 24 * 60 * 60,
|
||||
exp: Math.floor(Date.now() / 1000) + 30 * 24 * 60 * 60,
|
||||
iat: Math.floor(Date.now() / 1000),
|
||||
}, c.env.JWT_SECRET, "HS256")
|
||||
return c.json({
|
||||
|
||||
@@ -194,7 +194,7 @@ export default {
|
||||
user_email: user_email,
|
||||
user_id: user_id,
|
||||
// 90 days expire in seconds
|
||||
exp: Math.floor(Date.now() / 1000) + 90 * 24 * 60 * 60,
|
||||
exp: Math.floor(Date.now() / 1000) + 30 * 24 * 60 * 60,
|
||||
iat: Math.floor(Date.now() / 1000),
|
||||
}, c.env.JWT_SECRET, "HS256")
|
||||
return c.json({
|
||||
|
||||
@@ -55,10 +55,21 @@ export default {
|
||||
// 1 hour
|
||||
exp: Math.floor(Date.now() / 1000) + 3600,
|
||||
}, c.env.JWT_SECRET, "HS256") : null;
|
||||
// create new if expired in 7 days
|
||||
const new_user_token = user.exp > (
|
||||
Math.floor(Date.now() / 1000) + 7 * 24 * 60 * 60
|
||||
) ? null : await Jwt.sign({
|
||||
user_email: user.user_email,
|
||||
user_id: user.user_id,
|
||||
// 30 days expire in seconds
|
||||
exp: Math.floor(Date.now() / 1000) + 30 * 24 * 60 * 60,
|
||||
iat: Math.floor(Date.now() / 1000),
|
||||
}, c.env.JWT_SECRET, "HS256");
|
||||
return c.json({
|
||||
...user,
|
||||
is_admin: is_admin,
|
||||
access_token: access_token,
|
||||
new_user_token: new_user_token,
|
||||
user_role: user_role
|
||||
});
|
||||
},
|
||||
|
||||
@@ -173,7 +173,7 @@ export default {
|
||||
user_email: email,
|
||||
user_id: user_id,
|
||||
// 90 days expire in seconds
|
||||
exp: Math.floor(Date.now() / 1000) + 90 * 24 * 60 * 60,
|
||||
exp: Math.floor(Date.now() / 1000) + 30 * 24 * 60 * 60,
|
||||
iat: Math.floor(Date.now() / 1000),
|
||||
}, c.env.JWT_SECRET, "HS256")
|
||||
return c.json({
|
||||
|
||||
Reference in New Issue
Block a user