Skip to content

Commit

Permalink
feat: added debug flag in the SuperTokenConfig in the init() for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
IamMayankThakur committed Oct 26, 2023
1 parent 9bdbd48 commit 6c554e9
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 19 deletions.
11 changes: 7 additions & 4 deletions lib/build/framework/fastify/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
// @ts-nocheck
/// <reference types="node" />
export type { SessionRequest } from "./framework";
export declare const plugin: import("fastify").FastifyPluginCallback<Record<never, never>, import("http").Server>;
export declare const plugin: import("fastify").FastifyPluginCallback<
Record<never, never>,
import("fastify").RawServerDefault
>;
export declare const errorHandler: () => (
err: any,
req: import("fastify").FastifyRequest<
import("fastify/types/route").RouteGenericInterface,
import("http").Server,
import("fastify").RawServerDefault,
import("http").IncomingMessage
>,
res: import("fastify").FastifyReply<
import("http").Server,
import("fastify").RawServerDefault,
import("http").IncomingMessage,
import("http").ServerResponse,
import("http").ServerResponse<import("http").IncomingMessage>,
import("fastify/types/route").RouteGenericInterface,
unknown
>
Expand Down
2 changes: 1 addition & 1 deletion lib/build/framework/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export declare function setCookieForServerResponse(
expires: number,
path: string,
sameSite: "strict" | "lax" | "none"
): ServerResponse;
): ServerResponse<IncomingMessage>;
export declare function getCookieValueToSetInHeader(
prev: string | string[] | undefined,
val: string | string[],
Expand Down
15 changes: 7 additions & 8 deletions lib/build/logger.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lib/build/supertokens.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/build/types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions lib/ts/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import debug from "debug";
import { version } from "./version";
// import SuperTokens from "./supertokens";

const SUPERTOKENS_DEBUG_NAMESPACE = "com.supertokens";
/*
Expand All @@ -23,12 +24,10 @@ const SUPERTOKENS_DEBUG_NAMESPACE = "com.supertokens";
*/

function logDebugMessage(message: string) {
if (debug.enabled(SUPERTOKENS_DEBUG_NAMESPACE)) {
debug(SUPERTOKENS_DEBUG_NAMESPACE)(
`{t: "${new Date().toISOString()}", message: \"${message}\", file: \"${getFileLocation()}\" sdkVer: "${version}"}`
);
console.log();
}
debug(SUPERTOKENS_DEBUG_NAMESPACE)(
`{t: "${new Date().toISOString()}", message: \"${message}\", file: \"${getFileLocation()}\" sdkVer: "${version}"}`
);
console.log();
}

let getFileLocation = () => {
Expand Down
4 changes: 4 additions & 0 deletions lib/ts/supertokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import STError from "./error";
import { logDebugMessage } from "./logger";
import { PostSuperTokensInitCallbacks } from "./postSuperTokensInitCallbacks";
import { DEFAULT_TENANT_ID } from "./recipe/multitenancy/constants";
import debug from "debug";

export default class SuperTokens {
private static instance: SuperTokens | undefined;
Expand All @@ -49,6 +50,9 @@ export default class SuperTokens {
telemetryEnabled: boolean;

constructor(config: TypeInput) {
if (config.debug) {
debug.enable("com.supertokens");
}
logDebugMessage("Started SuperTokens with debug logging (supertokens.init called)");
const originToPrint =
config.appInfo.origin === undefined
Expand Down
1 change: 1 addition & 0 deletions lib/ts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type TypeInput = {
recipeList: RecipeListFunction[];
telemetry?: boolean;
isInServerlessEnv?: boolean;
debug?: boolean;
};

export type RecipeListFunction = (appInfo: NormalisedAppinfo, isInServerlessEnv: boolean) => RecipeModule;
Expand Down

0 comments on commit 6c554e9

Please sign in to comment.