mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-13 03:35:52 +01:00
9cd3ccb408
* fix: login without reload (#678) (#679) * fix: implements code review suggestions (#914) * refactor: adds scope to the app * refactor: handles null value from localstorage for username * refactor: removes text type from <Input /> * refactor: replaces isNull with isNil * refactor: improves makeLogin method * refactor: adds error from api constant * fix: updates error using API_ERROR constant in tests * refactor: updates regex for moduleMapper in jest config
26 lines
743 B
JavaScript
26 lines
743 B
JavaScript
/**
|
|
* Token Utility
|
|
*/
|
|
|
|
import { Base64 } from 'js-base64';
|
|
import addHours from 'date-fns/add_hours';
|
|
|
|
export function generateTokenWithTimeRange (limit = 0) {
|
|
const payload = {
|
|
username: 'verdaccio',
|
|
exp: Number.parseInt(addHours(new Date(), limit).getTime() / 1000, 10)
|
|
};
|
|
return `xxxxxx.${Base64.encode(JSON.stringify(payload))}.xxxxxx`;
|
|
}
|
|
|
|
export function generateTokenWithExpirationAsString () {
|
|
const payload = { username: 'verdaccio', exp: 'I am not a number' };
|
|
return `xxxxxx.${Base64.encode(payload)}.xxxxxx`;
|
|
}
|
|
|
|
export function generateTokenWithOutExpiration (){
|
|
const payload = {
|
|
username: 'verdaccio'
|
|
};
|
|
return `xxxxxx.${Base64.encode(JSON.stringify(payload))}.xxxxxx`;
|
|
} |