-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refresh token implementation, no token rotation yet, store in secure …
…cookie
- Loading branch information
1 parent
589ba69
commit 08105bd
Showing
9 changed files
with
128 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
import jwt from 'jsonwebtoken'; | ||
import { ACCESS_TOKEN_EXPIRY } from '../config/constants'; | ||
|
||
export default (tokendata) => { | ||
const getAccessToken = (tokendata) => { | ||
if (!tokendata) { | ||
throw Error('Token data missing.'); | ||
} | ||
|
||
const expiresIn = 60 * 60 * 24 * 7; // 7 days | ||
const expiresIn = ACCESS_TOKEN_EXPIRY; | ||
|
||
try { | ||
return jwt.sign(tokendata, process.env.JWT_SECRET, { expiresIn }); | ||
} | ||
catch (err) { | ||
console.log('Erro generating token', err); | ||
} | ||
}; | ||
}; | ||
|
||
export default getAccessToken; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const getRefreshToken = () => { | ||
const length = 36; | ||
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
|
||
let result = ''; | ||
for (var i = length; i > 0; --i) { | ||
result += chars[Math.floor(Math.random() * chars.length)]; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
export default getRefreshToken; |