File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff 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+ / J W T _ S E C R E T _ R E F R E S H _ T O K E N = ( .* ) ? / ,
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+
3456main ( )
57+ refreshTokenJWT ( )
You can’t perform that action at this time.
0 commit comments