whodis-react
Version:
React hooks and components for secure, best practices authentication in seconds
35 lines • 2.06 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAuthorizationHeader = void 0;
const getAuthableToken_1 = require("../token/getAuthableToken");
/**
* used to define the value of the authorization header, based on whether a user is logged in or not
* - if user is logged in, returns the bearer token header value
* - if user is not logged in, returns empty-string
* both of these values can be set as the `authorization` header - which the server will read to authenticate the user
*
* note: the type of authorization token that is sent will depend on the environment:
* - when client-side rendering, you'll find an anti-csrf token here
* - when server-side-rendering, you'll find the raw auth token itself here
*
* IMPORTANT: please make sure that this value is never logged out - as it could contain the raw auth token itself.
*/
const getAuthorizationHeader = ({ storage, }) => __awaiter(void 0, void 0, void 0, function* () {
// grab the token from storage
const token = yield (0, getAuthableToken_1.getAuthableToken)({ storage });
if (!token)
return ''; // if its not set, then no auth available
// set the authorization header w/ the bearer token scheme
return `Bearer ${token}`;
});
exports.getAuthorizationHeader = getAuthorizationHeader;
//# sourceMappingURL=getAuthorizationHeader.js.map