Skip to content

Commit 7bd762b

Browse files
committed
fix: update generate env jwt with refresh token
1 parent 0e8af7c commit 7bd762b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/scripts/generateEnvJWT.ts

+23
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,27 @@ function main() {
3131
}
3232
}
3333

34+
function refreshTokenJWT() {
35+
const pathRes = path.resolve('.env')
36+
const contentEnv = fs.readFileSync(pathRes, { encoding: 'utf-8' })
37+
const jwtSecret = getUniqueCodev2()
38+
const strJWT = `JWT_SECRET_REFRESH_TOKEN=${jwtSecret}`
39+
40+
if (contentEnv.includes('JWT_SECRET_REFRESH_TOKEN=')) {
41+
// Replace JWT SECRET REFRESH TOKEN jika sudah ada
42+
const replaceContent = contentEnv.replace(
43+
/JWT_SECRET_REFRESH_TOKEN=(.*)?/,
44+
strJWT
45+
)
46+
fs.writeFileSync(`${pathRes}`, replaceContent)
47+
console.log('Refresh JWT SECRET REFRESH TOKEN Success')
48+
} else {
49+
// Generate JWT SECRET REFRESH TOKEN kalo belum ada di environment
50+
const extraContent = `${strJWT}\n\n${contentEnv}`
51+
fs.writeFileSync(`${pathRes}`, extraContent)
52+
console.log('Generate JWT SECRET REFRESH TOKEN Success')
53+
}
54+
}
55+
3456
main()
57+
refreshTokenJWT()

0 commit comments

Comments
 (0)