fix(striker-ui-api): prefer original url over url/path of request

main
Tsu-ba-me 2 years ago
parent e460986e7c
commit 9337b3c881
  1. 6
      striker-ui-api/src/lib/assertAuthentication.ts
  2. 4
      striker-ui-api/src/session.ts

@ -29,7 +29,7 @@ export const assertAuthentication: AssertAuthenticationFunction = ({
let getReturnTo: ((...args: HandlerParameters) => string) | undefined; let getReturnTo: ((...args: HandlerParameters) => string) | undefined;
if (failReturnTo === true) { if (failReturnTo === true) {
getReturnTo = ({ path }) => path; getReturnTo = ({ originalUrl, url }) => originalUrl || url;
} else if (typeof failReturnTo === 'string') { } else if (typeof failReturnTo === 'string') {
getReturnTo = () => failReturnTo; getReturnTo = () => failReturnTo;
} }
@ -47,14 +47,14 @@ export const assertAuthentication: AssertAuthenticationFunction = ({
return (...args) => { return (...args) => {
const { 0: request } = args; const { 0: request } = args;
const { path, session } = request; const { originalUrl, session } = request;
const { passport } = session; const { passport } = session;
if (passport?.user) return succeed(...args); if (passport?.user) return succeed(...args);
const rt = getReturnTo?.call(null, ...args); const rt = getReturnTo?.call(null, ...args);
stdout(`Unauthenticated access to ${path}`); stdout(`Unauthenticated access to ${originalUrl}`);
if (rt) { if (rt) {
stdout(`Set session.returnTo=${rt}`); stdout(`Set session.returnTo=${rt}`);

@ -187,10 +187,10 @@ export default (async () =>
maxAge: DEFAULT_COOKIE_ORIGINAL_MAX_AGE, maxAge: DEFAULT_COOKIE_ORIGINAL_MAX_AGE,
secure: false, secure: false,
}, },
genid: ({ path }) => { genid: ({ originalUrl }) => {
const sid = uuid(); const sid = uuid();
stdout(`Generated session identifier ${sid}; request.path=${path}`); stdout(`Generated session identifier ${sid}; access to ${originalUrl}`);
return sid; return sid;
}, },

Loading…
Cancel
Save