Skip to content

Commit

Permalink
Add support for returning user-agent at top-level in session get endp…
Browse files Browse the repository at this point in the history
…oint
  • Loading branch information
deepjyoti30-st committed Oct 15, 2024
1 parent 8e12884 commit 5f6ce83
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
10 changes: 9 additions & 1 deletion lib/build/recipe/session/api/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const normalisedURLPath_1 = __importDefault(require("../../../normalisedURLPath"
const sessionRequestFunctions_1 = require("../sessionRequestFunctions");
const error_1 = __importDefault(require("../error"));
const __2 = require("../../..");
const constants_1 = require("../constants");
function getAPIInterface() {
return {
refreshPOST: async function ({ options, userContext }) {
Expand Down Expand Up @@ -97,7 +98,14 @@ function getAPIInterface() {
userContext
);
if (sessionInformation !== undefined) {
userSessions.push(sessionInformation);
userSessions.push(
Object.assign(Object.assign({}, sessionInformation), {
userAgent:
sessionInformation.sessionDataInDatabase[
constants_1.USER_AGENT_KEY_FOR_SESSION_DATA
],
})
);
}
resolve();
} catch (err) {
Expand Down
5 changes: 4 additions & 1 deletion lib/build/recipe/session/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export declare type APIInterface = {
}) => Promise<
| {
status: "OK";
sessions: SessionInformation[];
sessions: SessionInformationWithExtractedInformation[];
}
| SessionError
| GeneralErrorResponse
Expand Down Expand Up @@ -368,6 +368,9 @@ export declare type SessionInformation = {
timeCreated: number;
tenantId: string;
};
export declare type SessionInformationWithExtractedInformation = SessionInformation & {
userAgent: string | undefined;
};
export declare type ClaimValidationResult =
| {
isValid: true;
Expand Down
13 changes: 9 additions & 4 deletions lib/ts/recipe/session/api/implementation.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import SessionWrapper, { APIInterface, APIOptions, VerifySessionOptions } from "../";
import { normaliseHttpMethod } from "../../../utils";
import NormalisedURLPath from "../../../normalisedURLPath";
import { SessionContainerInterface, SessionInformation } from "../types";
import { SessionContainerInterface, SessionInformationWithExtractedInformation } from "../types";
import { GeneralErrorResponse, UserContext } from "../../../types";
import { getSessionFromRequest, refreshSessionInRequest } from "../sessionRequestFunctions";
import SessionError from "../error";
import { getUser } from "../../..";
import { USER_AGENT_KEY_FOR_SESSION_DATA } from "../constants";

export default function getAPIInterface(): APIInterface {
return {
Expand Down Expand Up @@ -91,7 +92,7 @@ export default function getAPIInterface(): APIInterface {
}): Promise<
| {
status: "OK";
sessions: SessionInformation[];
sessions: SessionInformationWithExtractedInformation[];
}
| SessionError
| GeneralErrorResponse
Expand Down Expand Up @@ -130,7 +131,7 @@ export default function getAPIInterface(): APIInterface {
// Since we need to fetch multiple sessions information,
// we are creating multiple promises for fetching the details
// and using a Promise.all() to resolve them together.
const userSessions: SessionInformation[] = [];
const userSessions: SessionInformationWithExtractedInformation[] = [];
const sessionGetPromises: Promise<void>[] = [];

allSessionHandles.forEach((sessionHandle) => {
Expand All @@ -142,7 +143,11 @@ export default function getAPIInterface(): APIInterface {
userContext
);
if (sessionInformation !== undefined) {
userSessions.push(sessionInformation);
userSessions.push({
...sessionInformation,
userAgent:
sessionInformation.sessionDataInDatabase[USER_AGENT_KEY_FOR_SESSION_DATA],
});
}

resolve();
Expand Down
6 changes: 5 additions & 1 deletion lib/ts/recipe/session/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export type APIInterface = {
}) => Promise<
| {
status: "OK";
sessions: SessionInformation[];
sessions: SessionInformationWithExtractedInformation[];
}
| SessionError
| GeneralErrorResponse
Expand Down Expand Up @@ -443,6 +443,10 @@ export type SessionInformation = {
tenantId: string;
};

export type SessionInformationWithExtractedInformation = SessionInformation & {
userAgent: string | undefined;
};

export type ClaimValidationResult = { isValid: true } | { isValid: false; reason?: JSONValue };
export type ClaimValidationError = {
id: string;
Expand Down

0 comments on commit 5f6ce83

Please sign in to comment.