@civic/auth 0.9.0-beta.2 → 0.9.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/dist/lib/logger.d.ts +6 -0
  3. package/dist/lib/logger.d.ts.map +1 -1
  4. package/dist/lib/logger.js +7 -0
  5. package/dist/lib/logger.js.map +1 -1
  6. package/dist/nextjs/config.d.ts +2 -4
  7. package/dist/nextjs/config.d.ts.map +1 -1
  8. package/dist/nextjs/config.js +4 -57
  9. package/dist/nextjs/config.js.map +1 -1
  10. package/dist/react-router-7/components/UserButton.d.ts +13 -0
  11. package/dist/react-router-7/components/UserButton.d.ts.map +1 -0
  12. package/dist/react-router-7/components/UserButton.js +108 -0
  13. package/dist/react-router-7/components/UserButton.js.map +1 -0
  14. package/dist/react-router-7/components/UserButtonPresentation.d.ts +10 -0
  15. package/dist/react-router-7/components/UserButtonPresentation.d.ts.map +1 -0
  16. package/dist/react-router-7/components/UserButtonPresentation.js +19 -0
  17. package/dist/react-router-7/components/UserButtonPresentation.js.map +1 -0
  18. package/dist/react-router-7/config.d.ts +69 -0
  19. package/dist/react-router-7/config.d.ts.map +1 -0
  20. package/dist/react-router-7/config.js +88 -0
  21. package/dist/react-router-7/config.js.map +1 -0
  22. package/dist/react-router-7/cookies.d.ts +40 -0
  23. package/dist/react-router-7/cookies.d.ts.map +1 -0
  24. package/dist/react-router-7/cookies.js +125 -0
  25. package/dist/react-router-7/cookies.js.map +1 -0
  26. package/dist/react-router-7/index.d.ts +10 -0
  27. package/dist/react-router-7/index.d.ts.map +1 -0
  28. package/dist/react-router-7/index.js +12 -0
  29. package/dist/react-router-7/index.js.map +1 -0
  30. package/dist/react-router-7/routeHandler.d.ts +51 -0
  31. package/dist/react-router-7/routeHandler.d.ts.map +1 -0
  32. package/dist/react-router-7/routeHandler.js +323 -0
  33. package/dist/react-router-7/routeHandler.js.map +1 -0
  34. package/dist/react-router-7/useUser.d.ts +43 -0
  35. package/dist/react-router-7/useUser.d.ts.map +1 -0
  36. package/dist/react-router-7/useUser.js +92 -0
  37. package/dist/react-router-7/useUser.js.map +1 -0
  38. package/dist/reactjs/core/GlobalAuthManager.d.ts +2 -1
  39. package/dist/reactjs/core/GlobalAuthManager.d.ts.map +1 -1
  40. package/dist/reactjs/core/GlobalAuthManager.js +16 -2
  41. package/dist/reactjs/core/GlobalAuthManager.js.map +1 -1
  42. package/dist/server/session.d.ts.map +1 -1
  43. package/dist/server/session.js +1 -0
  44. package/dist/server/session.js.map +1 -1
  45. package/dist/services/AuthenticationService.d.ts.map +1 -1
  46. package/dist/services/AuthenticationService.js +0 -5
  47. package/dist/services/AuthenticationService.js.map +1 -1
  48. package/dist/services/PKCE.d.ts.map +1 -1
  49. package/dist/services/PKCE.js +4 -1
  50. package/dist/services/PKCE.js.map +1 -1
  51. package/dist/shared/hooks/useCivicAuthConfig.d.ts +1 -1
  52. package/dist/shared/hooks/useCivicAuthConfig.d.ts.map +1 -1
  53. package/dist/shared/lib/cookieConfig.d.ts +46 -0
  54. package/dist/shared/lib/cookieConfig.d.ts.map +1 -0
  55. package/dist/shared/lib/cookieConfig.js +99 -0
  56. package/dist/shared/lib/cookieConfig.js.map +1 -0
  57. package/dist/shared/version.d.ts +1 -1
  58. package/dist/shared/version.d.ts.map +1 -1
  59. package/dist/shared/version.js +1 -1
  60. package/dist/shared/version.js.map +1 -1
  61. package/dist/types.d.ts +1 -1
  62. package/dist/types.d.ts.map +1 -1
  63. package/dist/types.js.map +1 -1
  64. package/dist/vanillajs/auth/CivicAuth.d.ts +1 -1
  65. package/dist/vanillajs/auth/CivicAuth.d.ts.map +1 -1
  66. package/dist/vanillajs/auth/CivicAuth.js +1 -0
  67. package/dist/vanillajs/auth/CivicAuth.js.map +1 -1
  68. package/dist/vanillajs/auth/handlers/MessageHandler.d.ts.map +1 -1
  69. package/dist/vanillajs/auth/handlers/MessageHandler.js +3 -0
  70. package/dist/vanillajs/auth/handlers/MessageHandler.js.map +1 -1
  71. package/package.json +13 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.9.1 Optional client ID
2
+
3
+ - Make client ID optional when login url is provided
4
+ - Add React Router 7 (formerly Remix) namespace and SDK
5
+
1
6
  # 0.9.0 Browser-specific auto-redirect
2
7
 
3
8
  - Add support for autp-redirecting users in iframe mode based on the browser it runs in. Can be toggled on/off using the 'autoRedirect' flag
@@ -18,6 +18,12 @@ export declare const loggers: {
18
18
  readonly hooks: Logger;
19
19
  readonly context: Logger;
20
20
  };
21
+ readonly reactRouter: {
22
+ readonly routes: Logger;
23
+ readonly handlers: {
24
+ readonly auth: Logger;
25
+ };
26
+ };
21
27
  readonly services: {
22
28
  readonly validation: Logger;
23
29
  readonly network: Logger;
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CAClD;AAsCD,eAAO,MAAM,YAAY,cAAe,MAAM,KAAG,MACrB,CAAC;AAG7B,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;CAoBV,CAAC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CAClD;AAsCD,eAAO,MAAM,YAAY,cAAe,MAAM,KAAG,MACrB,CAAC;AAG7B,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;CA2BV,CAAC"}
@@ -46,6 +46,13 @@ export const loggers = {
46
46
  hooks: createLogger("react:hooks"),
47
47
  context: createLogger("react:context"),
48
48
  },
49
+ // React Router specific loggers
50
+ reactRouter: {
51
+ routes: createLogger("react-router:routes"),
52
+ handlers: {
53
+ auth: createLogger("react-router:handlers:auth"),
54
+ },
55
+ },
49
56
  // Shared utilities loggers
50
57
  services: {
51
58
  validation: createLogger("utils:validation"),
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,YAAY,GAAG,aAAa,CAAC;AASnC,MAAM,WAAW;IACP,WAAW,CAAiB;IAC5B,UAAU,CAAiB;IAC3B,UAAU,CAAiB;IAC3B,WAAW,CAAiB;IAEpC,YAAY,SAAiB;QAC3B,+CAA+C;QAC/C,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,GAAG,YAAY,IAAI,SAAS,QAAQ,CAAC,CAAC;QAC/D,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,GAAG,YAAY,IAAI,SAAS,OAAO,CAAC,CAAC;QAC7D,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,GAAG,YAAY,IAAI,SAA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kBAAkB,CAAC;QAC5C,KAAK,EAAE,YAAY,CAAC,aAAa,CAAC;QAClC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC;KACvC;IACD,2BAA2B;IAC3B,QAAQ,EAAE;QACR,UAAU,EAAE,YAAY,CAAC,kBAAkB,CAAC;QAC5C,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC;KACvC;CACO,CAAC","sourcesContent":["import debug from \"debug\";\n\nconst PACKAGE_NAME = \"@civic/auth\";\n\nexport interface Logger {\n debug(message: string, ...args: unknown[]): void;\n info(message: string, ...args: unknown[]): void;\n warn(message: string, ...args: unknown[]): void;\n error(message: string, ...args: unknown[]): void;\n}\n\nclass DebugLogger implements Logger {\n private debugLogger: debug.Debugger;\n private infoLogger: debug.Debugger;\n private warnLogger: debug.Debugger;\n private errorLogger: debug.Debugger;\n\n constructor(namespace: string) {\n // Format: @org/package:library:component:level\n this.debugLogger = debug(`${PACKAGE_NAME}:${namespace}:debug`);\n this.infoLogger = debug(`${PACKAGE_NAME}:${namespace}:info`);\n this.warnLogger = debug(`${PACKAGE_NAME}:${namespace}:warn`);\n this.errorLogger = debug(`${PACKAGE_NAME}:${namespace}:error`);\n\n this.debugLogger.color = \"4\";\n this.infoLogger.color = \"2\";\n this.warnLogger.color = \"3\";\n this.errorLogger.color = \"1\";\n }\n\n debug(message: string, ...args: unknown[]): void {\n this.debugLogger(message, ...args);\n }\n\n info(message: string, ...args: unknown[]): void {\n this.infoLogger(message, ...args);\n }\n\n warn(message: string, ...args: unknown[]): void {\n this.warnLogger(message, ...args);\n }\n\n error(message: string, ...args: unknown[]): void {\n this.errorLogger(message, ...args);\n }\n}\n\nexport const createLogger = (namespace: string): Logger =>\n new DebugLogger(namespace);\n\n// Pre-configured loggers for different parts of the package\nexport const loggers = {\n // Next.js specific loggers\n nextjs: {\n routes: createLogger(\"api:routes\"),\n middleware: createLogger(\"api:middleware\"),\n handlers: {\n auth: createLogger(\"api:handlers:auth\"),\n },\n },\n // React specific loggers\n react: {\n components: createLogger(\"react:components\"),\n hooks: createLogger(\"react:hooks\"),\n context: createLogger(\"react:context\"),\n },\n // Shared utilities loggers\n services: {\n validation: createLogger(\"utils:validation\"),\n network: createLogger(\"utils:network\"),\n },\n} as const;\n"]}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,YAAY,GAAG,aAAa,CAAC;AASnC,MAAM,WAAW;IACP,WAAW,CAAiB;IAC5B,UAAU,CAAiB;IAC3B,UAAU,CAAiB;IAC3B,WAAW,CAAiB;IAEpC,YAAY,SAAiB;QAC3B,+CAA+C;QAC/C,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,GAAG,YAAY,IAAI,SAAS,QAAQ,CAAC,CAAC;QAC/D,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,GAAG,YAAY,IAAI,SAAS,OAAO,CAAC,CAAC;QAC7D,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,GAAG,YAAY,IAAI,SAAS,OAAO,CAAC,CAAC;QAC7D,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,GAAG,YAAY,IAAI,SAAS,QAAQ,CAAC,CAAC;QAE/D,IAAI,CAAC,WAAW,CAAC,KAAK,GAAG,GAAG,CAAC;QAC7B,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG,GAAG,CAAC;QAC5B,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG,GAAG,CAAC;QAC5B,IAAI,CAAC,WAAW,CAAC,KAAK,GAAG,GAAG,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;QACvC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,GAAG,IAAe;QACtC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,GAAG,IAAe;QACtC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;QACvC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACrC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,SAAiB,EAAU,EAAE,CACxD,IAAI,WAAW,CAAC,SAAS,CAAC,CAAC;AAE7B,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,2BAA2B;IAC3B,MAAM,EAAE;QACN,MAAM,EAAE,YAAY,CAAC,YAAY,CAAC;QAClC,UAAU,EAAE,YAAY,CAAC,gBAAgB,CAAC;QAC1C,QAAQ,EAAE;YACR,IAAI,EAAE,YAAY,CAAC,mBAAmB,CAAC;SACxC;KACF;IACD,yBAAyB;IACzB,KAAK,EAAE;QACL,UAAU,EAAE,YAAY,CAAC,kBAAkB,CAAC;QAC5C,KAAK,EAAE,YAAY,CAAC,aAAa,CAAC;QAClC,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC;KACvC;IACD,gCAAgC;IAChC,WAAW,EAAE;QACX,MAAM,EAAE,YAAY,CAAC,qBAAqB,CAAC;QAC3C,QAAQ,EAAE;YACR,IAAI,EAAE,YAAY,CAAC,4BAA4B,CAAC;SACjD;KACF;IACD,2BAA2B;IAC3B,QAAQ,EAAE;QACR,UAAU,EAAE,YAAY,CAAC,kBAAkB,CAAC;QAC5C,OAAO,EAAE,YAAY,CAAC,eAAe,CAAC;KACvC;CACO,CAAC","sourcesContent":["import debug from \"debug\";\n\nconst PACKAGE_NAME = \"@civic/auth\";\n\nexport interface Logger {\n debug(message: string, ...args: unknown[]): void;\n info(message: string, ...args: unknown[]): void;\n warn(message: string, ...args: unknown[]): void;\n error(message: string, ...args: unknown[]): void;\n}\n\nclass DebugLogger implements Logger {\n private debugLogger: debug.Debugger;\n private infoLogger: debug.Debugger;\n private warnLogger: debug.Debugger;\n private errorLogger: debug.Debugger;\n\n constructor(namespace: string) {\n // Format: @org/package:library:component:level\n this.debugLogger = debug(`${PACKAGE_NAME}:${namespace}:debug`);\n this.infoLogger = debug(`${PACKAGE_NAME}:${namespace}:info`);\n this.warnLogger = debug(`${PACKAGE_NAME}:${namespace}:warn`);\n this.errorLogger = debug(`${PACKAGE_NAME}:${namespace}:error`);\n\n this.debugLogger.color = \"4\";\n this.infoLogger.color = \"2\";\n this.warnLogger.color = \"3\";\n this.errorLogger.color = \"1\";\n }\n\n debug(message: string, ...args: unknown[]): void {\n this.debugLogger(message, ...args);\n }\n\n info(message: string, ...args: unknown[]): void {\n this.infoLogger(message, ...args);\n }\n\n warn(message: string, ...args: unknown[]): void {\n this.warnLogger(message, ...args);\n }\n\n error(message: string, ...args: unknown[]): void {\n this.errorLogger(message, ...args);\n }\n}\n\nexport const createLogger = (namespace: string): Logger =>\n new DebugLogger(namespace);\n\n// Pre-configured loggers for different parts of the package\nexport const loggers = {\n // Next.js specific loggers\n nextjs: {\n routes: createLogger(\"api:routes\"),\n middleware: createLogger(\"api:middleware\"),\n handlers: {\n auth: createLogger(\"api:handlers:auth\"),\n },\n },\n // React specific loggers\n react: {\n components: createLogger(\"react:components\"),\n hooks: createLogger(\"react:hooks\"),\n context: createLogger(\"react:context\"),\n },\n // React Router specific loggers\n reactRouter: {\n routes: createLogger(\"react-router:routes\"),\n handlers: {\n auth: createLogger(\"react-router:handlers:auth\"),\n },\n },\n // Shared utilities loggers\n services: {\n validation: createLogger(\"utils:validation\"),\n network: createLogger(\"utils:network\"),\n },\n} as const;\n"]}
@@ -1,9 +1,7 @@
1
1
  import type { NextConfig } from "next";
2
2
  import { type CookieConfig, type TokensCookieConfig } from "../shared/lib/types.js";
3
- export type CookiesConfigObject = {
4
- tokens: TokensCookieConfig;
5
- user: CookieConfig;
6
- };
3
+ import { type CookiesConfigObject } from "../shared/lib/cookieConfig.js";
4
+ export type { CookiesConfigObject };
7
5
  /**
8
6
  * Configuration values for Civic Auth.
9
7
  * Only clientId is required, all others are optional.
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/nextjs/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGvC,OAAO,EAEL,KAAK,YAAY,EAEjB,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAO/B,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,mBAAmB,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,OAAO,CACpC,sBAAsB,GACtB;IACE,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;QACrC,IAAI,CAAC,EAAE,YAAY,CAAC;KACrB,CAAC;CACH,CACJ,GAAG;IAGF,WAAW,CAAC,EA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AiC,CAAC;;wBAA+C,CAAC;eAAmD,CAAC;iBAA4C,CAAC;2BAAyC,CAAC;;;;;;;;;yBAA4zC,CAAC;6BAAwC,CAAC;;;eAAkD,CAAC;mBAAuB,CAAC;;;;CADh1iB,CAAC"}
@@ -1,12 +1,11 @@
1
1
  import { loggers } from "../lib/logger.js";
2
2
  import { withoutUndefined } from "../utils.js";
3
- import { CodeVerifier, OAuthTokenTypes, } from "../shared/lib/types.js";
4
- import { DEFAULT_AUTH_SERVER, MAX_COOKIE_AGE_SECONDS } from "../constants.js";
3
+ import {} from "../shared/lib/types.js";
4
+ import { DEFAULT_AUTH_SERVER } from "../constants.js";
5
5
  import { merge } from "ts-deepmerge";
6
6
  import { sanitizeBasePath } from "./utils.js";
7
+ import { createNextJSCookieConfig, } from "../shared/lib/cookieConfig.js";
7
8
  const logger = loggers.nextjs.handlers.auth;
8
- const defaultServerSecure = !(process.env.NODE_ENV === "development");
9
- const defaultCookiesMaxAge = 60 * 60; // 1 hour
10
9
  /**
11
10
  * Default configuration values that will be used if not overridden
12
11
  */
@@ -24,59 +23,7 @@ export const defaultAuthConfig = {
24
23
  basePath: "",
25
24
  baseUrl: undefined, // No default - will use request.nextUrl.origin when undefined
26
25
  autoRedirect: true, // Default to current behavior
27
- cookies: {
28
- tokens: {
29
- [OAuthTokenTypes.ID_TOKEN]: {
30
- secure: defaultServerSecure,
31
- httpOnly: true,
32
- sameSite: "strict",
33
- path: "/",
34
- maxAge: defaultCookiesMaxAge,
35
- },
36
- [OAuthTokenTypes.ACCESS_TOKEN]: {
37
- secure: defaultServerSecure,
38
- httpOnly: true,
39
- sameSite: "strict",
40
- path: "/",
41
- maxAge: defaultCookiesMaxAge,
42
- },
43
- [OAuthTokenTypes.REFRESH_TOKEN]: {
44
- secure: defaultServerSecure,
45
- httpOnly: true,
46
- sameSite: "strict",
47
- path: "/",
48
- maxAge: MAX_COOKIE_AGE_SECONDS,
49
- },
50
- [OAuthTokenTypes.OIDC_SESSION_EXPIRES_AT]: {
51
- secure: defaultServerSecure,
52
- httpOnly: false, // we need this to be available client-side
53
- sameSite: "strict",
54
- path: "/",
55
- maxAge: defaultCookiesMaxAge,
56
- },
57
- [CodeVerifier.COOKIE_NAME]: {
58
- secure: defaultServerSecure,
59
- httpOnly: true,
60
- sameSite: "strict",
61
- path: "/",
62
- maxAge: defaultCookiesMaxAge,
63
- },
64
- [CodeVerifier.APP_URL]: {
65
- secure: defaultServerSecure,
66
- httpOnly: true,
67
- sameSite: "strict",
68
- path: "/",
69
- maxAge: defaultCookiesMaxAge,
70
- },
71
- },
72
- user: {
73
- secure: defaultServerSecure,
74
- httpOnly: false, // we need this to be available client-side
75
- sameSite: "strict",
76
- path: "/",
77
- maxAge: defaultCookiesMaxAge,
78
- },
79
- },
26
+ cookies: createNextJSCookieConfig(),
80
27
  };
81
28
  /**
82
29
  * Resolves the authentication configuration by combining:
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/nextjs/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,YAAY,EAEZ,eAAe,GAEhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;AAmE5C,MAAM,mBAAmB,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC,CAAC;AACtE,MAAM,oBAAoB,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,SAAS;AAE/C;;GAEG;AACH,MAAM,CAAC,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AAmB,EAAE,cAAc,CAAC,WAAW;gBAC/C,wBAAwB,EAAE,cAAc,CAAC,WAAW;gBACpD,6BAA6B,EAAE,cAAc,CAAC,eAAe;gBAC7D,yBAAyB,EAAE,cAAc,CAAC,YAAY;gBACtD,qBAAqB,EAAE,cAAc,CAAC,QAAQ;gBAC9C,sBAAsB,EAAE,cAAc,CAAC,SAAS;gBAChD,+BAA+B,EAAE,cAAc,CAAC,iBAAiB;gBACjE,uBAAuB,EAAE,cAAc,CAAC,UAAU;gBAClD,oBAAoB,EAAE,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;gBACtD,oBAAoB,EAAE,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;gBACtD,yBAAyB,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC;gBACjE,qBAAqB,EAAE,cAAc,CAAC,QAAQ;gBAC9C,oBAAoB,EAAE,cAAc,CAAC,OAAO;gBAC5C,yBAAyB,EAAE,cAAc,CAAC,YAAY,CAAC,QAAQ,EAAE;aAClE;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable turbo/no-undeclared-env-vars */\nimport type { NextConfig } from \"next\";\nimport { loggers } from \"@/lib/logger.js\";\nimport { withoutUndefined } from \"@/utils.js\";\nimport {\n CodeVerifier,\n type CookieConfig,\n OAuthTokenTypes,\n type TokensCookieConfig,\n} from \"@/shared/lib/types.js\";\nimport { DEFAULT_AUTH_SERVER, MAX_COOKIE_AGE_SECONDS } from \"@/constants.js\";\nimport { merge } from \"ts-deepmerge\";\nimport { sanitizeBasePath } from \"./utils.js\";\n\nconst logger = loggers.nextjs.handlers.auth;\n\nexport type CookiesConfigObject = {\n tokens: TokensCookieConfig;\n user: CookieConfig;\n};\n\n/**\n * Configuration values for Civic Auth.\n * Only clientId is required, all others are optional.\n */\nexport type AuthConfigWithDefaults = {\n clientId: string;\n oauthServer: string;\n callbackUrl: string; // where Civic's internal OAuth callback is hosted\n loginSuccessUrl?: string; // where the user should be sent after the entire login completes, including the token exchange\n loginUrl: string;\n logoutUrl: string;\n logoutCallbackUrl: string;\n challengeUrl: string;\n refreshUrl: string;\n include: string[];\n exclude: string[];\n cookies: CookiesConfigObject;\n basePath?: string;\n baseUrl?: string; // Public domain for apps behind reverse proxies (e.g., \"https://myapp.com\")\n autoRedirect: boolean;\n};\n\n/**\n * All possible config values for Civic Auth\n */\nexport type OptionalAuthConfig = Partial<\n | AuthConfigWithDefaults\n | {\n cookies?: {\n tokens?: Partial<TokensCookieConfig>;\n user?: CookieConfig;\n };\n }\n> & {\n // Ensure TypeScript understands these properties are available\n // This doesn't change the public API, just helps TypeScript internally\n callbackUrl?: string; // where Civic's internal OAuth callback is hosted\n loginSuccessUrl?: string; // where the user should be sent after the entire login completes, including the token exchange\n loginUrl?: string;\n logoutUrl?: string;\n logoutCallbackUrl?: string;\n challengeUrl?: string;\n refreshUrl?: string;\n include?: string[];\n exclude?: string[];\n basePath?: string;\n baseUrl?: string;\n oauthServer?: string;\n autoRedirect?: boolean;\n};\n\n/**\n * Configuration values for Civic Auth.\n * Only clientId is required, all others are optional.\n */\nexport type AuthConfig = OptionalAuthConfig & {\n clientId: string;\n exclude?: string[];\n};\n\nconst defaultServerSecure = !(process.env.NODE_ENV === \"development\");\nconst defaultCookiesMaxAge = 60 * 60; // 1 hour\n\n/**\n * Default configuration values that will be used if not overridden\n */\nexport const defaultAuthConfig: Omit<AuthConfigWithDefaults, \"clientId\"> = {\n oauthServer: DEFAULT_AUTH_SERVER,\n callbackUrl: \"/api/auth/callback\",\n loginSuccessUrl: undefined, // By default, the user is sent to the redirect_url\n challengeUrl: \"/api/auth/challenge\",\n refreshUrl: \"/api/auth/refresh\",\n logoutUrl: \"/api/auth/logout\",\n logoutCallbackUrl: \"/api/auth/logoutcallback\",\n loginUrl: \"/\",\n include: [\"/**\"],\n exclude: [\"/api/auth/**\"],\n basePath: \"\",\n baseUrl: undefined, // No default - will use request.nextUrl.origin when undefined\n autoRedirect: true, // Default to current behavior\n cookies: {\n tokens: {\n [OAuthTokenTypes.ID_TOKEN]: {\n secure: defaultServerSecure,\n httpOnly: true,\n sameSite: \"strict\",\n path: \"/\",\n maxAge: defaultCookiesMaxAge,\n },\n [OAuthTokenTypes.ACCESS_TOKEN]: {\n secure: defaultServerSecure,\n httpOnly: true,\n sameSite: \"strict\",\n path: \"/\",\n maxAge: defaultCookiesMaxAge,\n },\n [OAuthTokenTypes.REFRESH_TOKEN]: {\n secure: defaultServerSecure,\n httpOnly: true,\n sameSite: \"strict\",\n path: \"/\",\n maxAge: MAX_COOKIE_AGE_SECONDS,\n },\n [OAuthTokenTypes.OIDC_SESSION_EXPIRES_AT]: {\n secure: defaultServerSecure,\n httpOnly: false, // we need this to be available client-side\n sameSite: \"strict\",\n path: \"/\",\n maxAge: defaultCookiesMaxAge,\n },\n [CodeVerifier.COOKIE_NAME]: {\n secure: defaultServerSecure,\n httpOnly: true,\n sameSite: \"strict\",\n path: \"/\",\n maxAge: defaultCookiesMaxAge,\n },\n [CodeVerifier.APP_URL]: {\n secure: defaultServerSecure,\n httpOnly: true,\n sameSite: \"strict\",\n path: \"/\",\n maxAge: defaultCookiesMaxAge,\n },\n },\n user: {\n secure: defaultServerSecure,\n httpOnly: false, // we need this to be available client-side\n sameSite: \"strict\",\n path: \"/\",\n maxAge: defaultCookiesMaxAge,\n },\n },\n};\n\n/**\n * Resolves the authentication configuration by combining:\n * 1. Default values\n * 2. Environment variables (set internally by the plugin)\n * 3. Explicitly passed configuration\n *\n * Config will be merged deeply, with arrays not merged, so that the\n * default include list (for example) [\"/*\"] will not be added\n *\n * Note: Developers should not set _civic_auth_* environment variables directly.\n * Instead, pass configuration to the createCivicAuthPlugin in next.config.js:\n *\n * @example\n * ```js\n * // next.config.js\n * export default createCivicAuthPlugin({\n * callbackUrl: '/custom/callback',\n * })\n * ```\n */\nexport const resolveAuthConfig = (\n config: Partial<AuthConfig> = {},\n): AuthConfigWithDefaults => {\n // Read configuration that was set by the plugin via environment variables\n const configFromEnv = withoutUndefined({\n clientId: process.env._civic_auth_client_id,\n oauthServer: process.env._civic_oauth_server,\n callbackUrl: process.env._civic_auth_callback_url,\n loginSuccessUrl: process.env._civic_auth_login_success_url,\n challengeUrl: process.env._civic_auth_challenge_url,\n loginUrl: process.env._civic_auth_login_url,\n logoutUrl: process.env._civic_auth_logout_url,\n logoutCallbackUrl: process.env._civic_auth_logout_callback_url,\n refreshUrl: process.env._civic_auth_refresh_url,\n include: process.env._civic_auth_includes?.split(\",\"),\n exclude: process.env._civic_auth_excludes?.split(\",\"),\n cookies: process.env._civic_auth_cookie_config\n ? JSON.parse(process.env._civic_auth_cookie_config)\n : undefined,\n basePath: process.env._civic_auth_base_path || \"\",\n baseUrl: process.env._civic_auth_base_url,\n autoRedirect:\n process.env._civic_auth_auto_redirect === \"false\" ? false : undefined,\n }) as AuthConfig;\n\n // Ensure \"/api/auth/**\" is always excluded\n const finalExclude = new Set([\n ...defaultAuthConfig.exclude,\n ...(configFromEnv.exclude || []),\n ...(config.exclude ?? []),\n ]);\n\n // Perform a deep merge of the configurations\n const mergedConfig = merge.withOptions(\n { mergeArrays: false },\n defaultAuthConfig,\n configFromEnv,\n config,\n );\n\n // Override the exclude list with the ensured list\n mergedConfig.exclude = Array.from(finalExclude);\n\n if (mergedConfig.clientId === undefined) {\n throw new Error(\"Civic Auth client ID is required\");\n }\n\n return mergedConfig as AuthConfigWithDefaults & { clientId: string };\n};\n\n/**\n * Creates a Next.js plugin that handles auth configuration.\n *\n * This is the main configuration point for the auth system.\n * Do not set _civic_auth_* environment variables directly - instead,\n * pass your configuration here.\n *\n * The only required field is clientId.\n *\n * Notes:\n * - If you provide explicit URLs, they will be used exactly as provided.\n * - Default URLs will automatically include the basePath from your Next.js config.\n *\n * @example\n * ```js\n * // next.config.js\n * export default createCivicAuthPlugin({\n * clientId: 'my-client-id',\n * });\n * ```\n *\n * @example\n * ```js\n * // next.config.js\n * export default createCivicAuthPlugin({\n * clientId: 'my-client-id',\n * callbackUrl: '/custom/callback',\n * loginUrl: '/custom/login',\n * logoutUrl: '/custom/logout',\n * logoutCallbackUrl: '/custom/logoutcallback',\n * include: ['/protected/*'],\n * exclude: ['/public/*']\n * })\n * ```\n *\n * The plugin sets internal environment variables that are used by\n * the auth system. These variables should not be set manually.\n */\nexport const createCivicAuthPlugin = (authConfig: AuthConfig) => {\n return (nextConfig?: NextConfig) => {\n logger.debug(\n \"createCivicAuthPlugin nextConfig\",\n JSON.stringify(nextConfig, null, 2),\n );\n\n // Extract basePath from Next.js config\n const basePath = sanitizeBasePath(nextConfig?.basePath || \"\");\n\n // Create a copy of default URLs with basePath added\n const defaultUrlsWithBasePath: Partial<AuthConfig> = {};\n\n // Only apply to URLs that aren't explicitly set in authConfig\n if (basePath) {\n if (!authConfig.callbackUrl)\n defaultUrlsWithBasePath.callbackUrl = `${basePath}/api/auth/callback`;\n if (!authConfig.challengeUrl)\n defaultUrlsWithBasePath.challengeUrl = `${basePath}/api/auth/challenge`;\n if (!authConfig.refreshUrl)\n defaultUrlsWithBasePath.refreshUrl = `${basePath}/api/auth/refresh`;\n if (!authConfig.logoutUrl)\n defaultUrlsWithBasePath.logoutUrl = `${basePath}/api/auth/logout`;\n if (!authConfig.logoutCallbackUrl)\n defaultUrlsWithBasePath.logoutCallbackUrl = `${basePath}/api/auth/logoutcallback`;\n if (!authConfig.loginUrl && authConfig.loginUrl !== \"\")\n defaultUrlsWithBasePath.loginUrl = basePath;\n }\n\n // Create final config with basePath and possibly modified URLs\n const resolvedConfig = resolveAuthConfig({\n ...defaultUrlsWithBasePath,\n ...authConfig,\n basePath,\n });\n\n return {\n ...nextConfig,\n env: {\n ...nextConfig?.env,\n // Internal environment variables - do not set these manually\n _civic_auth_client_id: resolvedConfig.clientId,\n _civic_oauth_server: resolvedConfig.oauthServer,\n _civic_auth_callback_url: resolvedConfig.callbackUrl,\n _civic_auth_login_success_url: resolvedConfig.loginSuccessUrl,\n _civic_auth_challenge_url: resolvedConfig.challengeUrl,\n _civic_auth_login_url: resolvedConfig.loginUrl,\n _civic_auth_logout_url: resolvedConfig.logoutUrl,\n _civic_auth_logout_callback_url: resolvedConfig.logoutCallbackUrl,\n _civic_auth_refresh_url: resolvedConfig.refreshUrl,\n _civic_auth_includes: resolvedConfig.include.join(\",\"),\n _civic_auth_excludes: resolvedConfig.exclude.join(\",\"),\n _civic_auth_cookie_config: JSON.stringify(resolvedConfig.cookies),\n _civic_auth_base_path: resolvedConfig.basePath,\n _civic_auth_base_url: resolvedConfig.baseUrl,\n _civic_auth_auto_redirect: resolvedConfig.autoRedirect.toString(),\n },\n };\n };\n};\n"]}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/nextjs/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAGN,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,wBAAwB,GAEzB,MAAM,8BAA8B,CAAC;AAKtC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;AA8D5C;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA6C;IACzE,WAAW,EAAE,mBAAmB;IAChC,WAAW,EAAE,oBAAoB;IACjC,eAAe,EAAE,SAAS,EAAE,mDAAmD;IAC/E,YAAY,EAAE,qBAAqB;IACnC,UAAU,EAAE,mBAAmB;IAC/B,SAAS,EAAE,kBAAkB;IAC7B,iBAAiB,EAAE,0BAA0B;IAC7C,QAAQ,EAAE,GAAG;IACb,OAAO,EAAE,CAA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E,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;gBACtD,oBAAoB,EAAE,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;gBACtD,yBAAyB,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC;gBACjE,qBAAqB,EAAE,cAAc,CAAC,QAAQ;gBAC9C,oBAAoB,EAAE,cAAc,CAAC,OAAO;gBAC5C,yBAAyB,EAAE,cAAc,CAAC,YAAY,CAAC,QAAQ,EAAE;aAClE;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable turbo/no-undeclared-env-vars */\nimport type { NextConfig } from \"next\";\nimport { loggers } from \"@/lib/logger.js\";\nimport { withoutUndefined } from \"@/utils.js\";\nimport {\n type CookieConfig,\n type TokensCookieConfig,\n} from \"@/shared/lib/types.js\";\nimport { DEFAULT_AUTH_SERVER } from \"@/constants.js\";\nimport { merge } from \"ts-deepmerge\";\nimport { sanitizeBasePath } from \"./utils.js\";\nimport {\n createNextJSCookieConfig,\n type CookiesConfigObject,\n} from \"@/shared/lib/cookieConfig.js\";\n\n// Re-export the shared type for public API\nexport type { CookiesConfigObject };\n\nconst logger = loggers.nextjs.handlers.auth;\n\n/**\n * Configuration values for Civic Auth.\n * Only clientId is required, all others are optional.\n */\nexport type AuthConfigWithDefaults = {\n clientId: string;\n oauthServer: string;\n callbackUrl: string; // where Civic's internal OAuth callback is hosted\n loginSuccessUrl?: string; // where the user should be sent after the entire login completes, including the token exchange\n loginUrl: string;\n logoutUrl: string;\n logoutCallbackUrl: string;\n challengeUrl: string;\n refreshUrl: string;\n include: string[];\n exclude: string[];\n cookies: CookiesConfigObject;\n basePath?: string;\n baseUrl?: string; // Public domain for apps behind reverse proxies (e.g., \"https://myapp.com\")\n autoRedirect: boolean;\n};\n\n/**\n * All possible config values for Civic Auth\n */\nexport type OptionalAuthConfig = Partial<\n | AuthConfigWithDefaults\n | {\n cookies?: {\n tokens?: Partial<TokensCookieConfig>;\n user?: CookieConfig;\n };\n }\n> & {\n // Ensure TypeScript understands these properties are available\n // This doesn't change the public API, just helps TypeScript internally\n callbackUrl?: string; // where Civic's internal OAuth callback is hosted\n loginSuccessUrl?: string; // where the user should be sent after the entire login completes, including the token exchange\n loginUrl?: string;\n logoutUrl?: string;\n logoutCallbackUrl?: string;\n challengeUrl?: string;\n refreshUrl?: string;\n include?: string[];\n exclude?: string[];\n basePath?: string;\n baseUrl?: string;\n oauthServer?: string;\n autoRedirect?: boolean;\n};\n\n/**\n * Configuration values for Civic Auth.\n * Only clientId is required, all others are optional.\n */\nexport type AuthConfig = OptionalAuthConfig & {\n clientId: string;\n exclude?: string[];\n};\n\n/**\n * Default configuration values that will be used if not overridden\n */\nexport const defaultAuthConfig: Omit<AuthConfigWithDefaults, \"clientId\"> = {\n oauthServer: DEFAULT_AUTH_SERVER,\n callbackUrl: \"/api/auth/callback\",\n loginSuccessUrl: undefined, // By default, the user is sent to the redirect_url\n challengeUrl: \"/api/auth/challenge\",\n refreshUrl: \"/api/auth/refresh\",\n logoutUrl: \"/api/auth/logout\",\n logoutCallbackUrl: \"/api/auth/logoutcallback\",\n loginUrl: \"/\",\n include: [\"/**\"],\n exclude: [\"/api/auth/**\"],\n basePath: \"\",\n baseUrl: undefined, // No default - will use request.nextUrl.origin when undefined\n autoRedirect: true, // Default to current behavior\n cookies: createNextJSCookieConfig(),\n};\n\n/**\n * Resolves the authentication configuration by combining:\n * 1. Default values\n * 2. Environment variables (set internally by the plugin)\n * 3. Explicitly passed configuration\n *\n * Config will be merged deeply, with arrays not merged, so that the\n * default include list (for example) [\"/*\"] will not be added\n *\n * Note: Developers should not set _civic_auth_* environment variables directly.\n * Instead, pass configuration to the createCivicAuthPlugin in next.config.js:\n *\n * @example\n * ```js\n * // next.config.js\n * export default createCivicAuthPlugin({\n * callbackUrl: '/custom/callback',\n * })\n * ```\n */\nexport const resolveAuthConfig = (\n config: Partial<AuthConfig> = {},\n): AuthConfigWithDefaults => {\n // Read configuration that was set by the plugin via environment variables\n const configFromEnv = withoutUndefined({\n clientId: process.env._civic_auth_client_id,\n oauthServer: process.env._civic_oauth_server,\n callbackUrl: process.env._civic_auth_callback_url,\n loginSuccessUrl: process.env._civic_auth_login_success_url,\n challengeUrl: process.env._civic_auth_challenge_url,\n loginUrl: process.env._civic_auth_login_url,\n logoutUrl: process.env._civic_auth_logout_url,\n logoutCallbackUrl: process.env._civic_auth_logout_callback_url,\n refreshUrl: process.env._civic_auth_refresh_url,\n include: process.env._civic_auth_includes?.split(\",\"),\n exclude: process.env._civic_auth_excludes?.split(\",\"),\n cookies: process.env._civic_auth_cookie_config\n ? JSON.parse(process.env._civic_auth_cookie_config)\n : undefined,\n basePath: process.env._civic_auth_base_path || \"\",\n baseUrl: process.env._civic_auth_base_url,\n autoRedirect:\n process.env._civic_auth_auto_redirect === \"false\" ? false : undefined,\n }) as AuthConfig;\n\n // Ensure \"/api/auth/**\" is always excluded\n const finalExclude = new Set([\n ...defaultAuthConfig.exclude,\n ...(configFromEnv.exclude || []),\n ...(config.exclude ?? []),\n ]);\n\n // Perform a deep merge of the configurations\n const mergedConfig = merge.withOptions(\n { mergeArrays: false },\n defaultAuthConfig,\n configFromEnv,\n config,\n );\n\n // Override the exclude list with the ensured list\n mergedConfig.exclude = Array.from(finalExclude);\n\n if (mergedConfig.clientId === undefined) {\n throw new Error(\"Civic Auth client ID is required\");\n }\n\n return mergedConfig as AuthConfigWithDefaults & { clientId: string };\n};\n\n/**\n * Creates a Next.js plugin that handles auth configuration.\n *\n * This is the main configuration point for the auth system.\n * Do not set _civic_auth_* environment variables directly - instead,\n * pass your configuration here.\n *\n * The only required field is clientId.\n *\n * Notes:\n * - If you provide explicit URLs, they will be used exactly as provided.\n * - Default URLs will automatically include the basePath from your Next.js config.\n *\n * @example\n * ```js\n * // next.config.js\n * export default createCivicAuthPlugin({\n * clientId: 'my-client-id',\n * });\n * ```\n *\n * @example\n * ```js\n * // next.config.js\n * export default createCivicAuthPlugin({\n * clientId: 'my-client-id',\n * callbackUrl: '/custom/callback',\n * loginUrl: '/custom/login',\n * logoutUrl: '/custom/logout',\n * logoutCallbackUrl: '/custom/logoutcallback',\n * include: ['/protected/*'],\n * exclude: ['/public/*']\n * })\n * ```\n *\n * The plugin sets internal environment variables that are used by\n * the auth system. These variables should not be set manually.\n */\nexport const createCivicAuthPlugin = (authConfig: AuthConfig) => {\n return (nextConfig?: NextConfig) => {\n logger.debug(\n \"createCivicAuthPlugin nextConfig\",\n JSON.stringify(nextConfig, null, 2),\n );\n\n // Extract basePath from Next.js config\n const basePath = sanitizeBasePath(nextConfig?.basePath || \"\");\n\n // Create a copy of default URLs with basePath added\n const defaultUrlsWithBasePath: Partial<AuthConfig> = {};\n\n // Only apply to URLs that aren't explicitly set in authConfig\n if (basePath) {\n if (!authConfig.callbackUrl)\n defaultUrlsWithBasePath.callbackUrl = `${basePath}/api/auth/callback`;\n if (!authConfig.challengeUrl)\n defaultUrlsWithBasePath.challengeUrl = `${basePath}/api/auth/challenge`;\n if (!authConfig.refreshUrl)\n defaultUrlsWithBasePath.refreshUrl = `${basePath}/api/auth/refresh`;\n if (!authConfig.logoutUrl)\n defaultUrlsWithBasePath.logoutUrl = `${basePath}/api/auth/logout`;\n if (!authConfig.logoutCallbackUrl)\n defaultUrlsWithBasePath.logoutCallbackUrl = `${basePath}/api/auth/logoutcallback`;\n if (!authConfig.loginUrl && authConfig.loginUrl !== \"\")\n defaultUrlsWithBasePath.loginUrl = basePath;\n }\n\n // Create final config with basePath and possibly modified URLs\n const resolvedConfig = resolveAuthConfig({\n ...defaultUrlsWithBasePath,\n ...authConfig,\n basePath,\n });\n\n return {\n ...nextConfig,\n env: {\n ...nextConfig?.env,\n // Internal environment variables - do not set these manually\n _civic_auth_client_id: resolvedConfig.clientId,\n _civic_oauth_server: resolvedConfig.oauthServer,\n _civic_auth_callback_url: resolvedConfig.callbackUrl,\n _civic_auth_login_success_url: resolvedConfig.loginSuccessUrl,\n _civic_auth_challenge_url: resolvedConfig.challengeUrl,\n _civic_auth_login_url: resolvedConfig.loginUrl,\n _civic_auth_logout_url: resolvedConfig.logoutUrl,\n _civic_auth_logout_callback_url: resolvedConfig.logoutCallbackUrl,\n _civic_auth_refresh_url: resolvedConfig.refreshUrl,\n _civic_auth_includes: resolvedConfig.include.join(\",\"),\n _civic_auth_excludes: resolvedConfig.exclude.join(\",\"),\n _civic_auth_cookie_config: JSON.stringify(resolvedConfig.cookies),\n _civic_auth_base_path: resolvedConfig.basePath,\n _civic_auth_base_url: resolvedConfig.baseUrl,\n _civic_auth_auto_redirect: resolvedConfig.autoRedirect.toString(),\n },\n };\n };\n};\n"]}
@@ -0,0 +1,13 @@
1
+ import type { BaseUser } from "../../types.js";
2
+ interface UserButtonProps {
3
+ className?: string;
4
+ style?: React.CSSProperties;
5
+ onSignIn?: (user: BaseUser | undefined) => void;
6
+ onSignOut?: () => void;
7
+ clientId?: string;
8
+ oauthServerBaseUrl?: string;
9
+ baseUrl?: string;
10
+ }
11
+ export declare function UserButton({ className, style, onSignIn, onSignOut, }: UserButtonProps): import("@emotion/react/jsx-runtime").JSX.Element;
12
+ export {};
13
+ //# sourceMappingURL=UserButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserButton.d.ts","sourceRoot":"","sources":["../../../src/react-router-7/components/UserButton.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,UAAU,eAAe;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC;IAChD,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAoCD,wBAAgB,UAAU,CAAC,EACzB,SAAS,EACT,KAAK,EACL,QAAQ,EACR,SAAS,GACV,EAAE,eAAe,oDAmKjB"}
@@ -0,0 +1,108 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
+ import { useEffect, useState, useRef, useCallback } from "react";
3
+ import { useUser } from "../useUser.js";
4
+ import { UserButtonPresentation } from "./UserButtonPresentation.js";
5
+ const ChevronDown = () => (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", className: "lucide lucide-chevron-down", children: _jsx("path", { d: "m6 9 6 6 6-6" }) }));
6
+ const ChevronUp = () => (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", className: "lucide lucide-chevron-up", children: _jsx("path", { d: "m18 15-6-6-6 6" }) }));
7
+ export function UserButton({ className, style, onSignIn, onSignOut, }) {
8
+ const { user, isLoggedIn, signIn, signOut } = useUser();
9
+ const [isAuthenticating, setIsAuthenticating] = useState(false);
10
+ const [isOpen, setIsOpen] = useState(false);
11
+ const [buttonWidth, setButtonWidth] = useState(null);
12
+ const buttonRef = useRef(null);
13
+ const dropdownRef = useRef(null);
14
+ useEffect(() => {
15
+ if (buttonRef.current) {
16
+ setButtonWidth(buttonRef.current.offsetWidth);
17
+ }
18
+ }, [isOpen]);
19
+ const handleClickOutside = useCallback((event) => {
20
+ const target = event.target;
21
+ if (buttonRef.current &&
22
+ dropdownRef.current &&
23
+ !buttonRef.current.contains(target) &&
24
+ !dropdownRef.current.contains(target)) {
25
+ setIsOpen(false);
26
+ }
27
+ }, []);
28
+ const handleEscape = useCallback((event) => {
29
+ if (event.key === "Escape") {
30
+ setIsOpen(false);
31
+ setIsAuthenticating(false);
32
+ }
33
+ }, []);
34
+ useEffect(() => {
35
+ if (isOpen) {
36
+ window.addEventListener("click", handleClickOutside);
37
+ window.addEventListener("keydown", handleEscape);
38
+ }
39
+ return () => {
40
+ window.removeEventListener("click", handleClickOutside);
41
+ window.removeEventListener("keydown", handleEscape);
42
+ };
43
+ }, [handleClickOutside, handleEscape, isOpen]);
44
+ const handleSignOut = async () => {
45
+ try {
46
+ await signOut();
47
+ onSignOut?.();
48
+ }
49
+ catch (error) {
50
+ console.error("❌ Sign out error:", error);
51
+ }
52
+ finally {
53
+ setIsOpen(false);
54
+ }
55
+ };
56
+ return (_jsx(_Fragment, { children: _jsxs("div", { style: { position: "relative", width: "auto" }, id: "civic-dropdown-container", children: [_jsx("div", { ref: buttonRef, children: _jsx(UserButtonPresentation, { className: className, onClick: async () => {
57
+ if (isLoggedIn) {
58
+ setIsOpen(!isOpen);
59
+ return;
60
+ }
61
+ const { user } = await signIn({ displayMode: "iframe" });
62
+ onSignIn?.(user);
63
+ }, "data-testid": "sign-in-button", style: {
64
+ ...style,
65
+ display: "flex",
66
+ alignItems: "center",
67
+ justifyContent: "center",
68
+ gap: "0.5rem",
69
+ minWidth: "10rem",
70
+ cursor: isAuthenticating ? "wait" : "pointer",
71
+ textAlign: "center",
72
+ opacity: isAuthenticating ? 0.7 : 1,
73
+ }, children: isLoggedIn ? (_jsxs(_Fragment, { children: [user?.picture && (_jsx("span", { style: {
74
+ position: "relative",
75
+ display: "flex",
76
+ height: "1.5rem",
77
+ width: "1.5rem",
78
+ flexShrink: 0,
79
+ gap: "0.5rem",
80
+ overflow: "hidden",
81
+ borderRadius: "9999px",
82
+ }, children: _jsx("img", { style: {
83
+ height: "100%",
84
+ width: "100%",
85
+ objectFit: "cover",
86
+ }, src: user.picture, alt: user?.name || user?.email }) })), _jsx("span", { children: user?.name || user?.email }), _jsx("span", { children: isOpen ? _jsx(ChevronUp, {}) : _jsx(ChevronDown, {}) })] })) : (_jsx("span", { children: isAuthenticating ? "Signing in..." : "Sign in" })) }) }), isLoggedIn && isOpen && (_jsx("div", { ref: dropdownRef, style: {
87
+ position: "absolute",
88
+ left: 0,
89
+ background: "white",
90
+ width: buttonWidth || "auto",
91
+ marginTop: "0.5rem",
92
+ borderRadius: "0.5rem",
93
+ boxShadow: "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",
94
+ zIndex: 1000,
95
+ }, children: _jsx("ul", { style: { listStyleType: "none", margin: 0, padding: 0 }, children: _jsx("li", { children: _jsx("button", { style: {
96
+ display: "block",
97
+ width: "100%",
98
+ padding: "0.5rem 1rem",
99
+ transition: "background-color 0.2s",
100
+ textAlign: "center",
101
+ color: "#6b7280",
102
+ cursor: "pointer",
103
+ borderRadius: "0.5rem",
104
+ border: "none",
105
+ background: "transparent",
106
+ }, onClick: handleSignOut, children: "Logout" }) }) }) }))] }) }));
107
+ }
108
+ //# sourceMappingURL=UserButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserButton.js","sourceRoot":"","sources":["../../../src/react-router-7/components/UserButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAarE,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,CACxB,cACE,KAAK,EAAC,4BAA4B,EAClC,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,GAAG,EACf,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,EACtB,SAAS,EAAC,4BAA4B,YAEtC,eAAM,C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Effect, useState, useRef, useCallback } from \"react\";\nimport { useUser } from \"../useUser.js\";\nimport { UserButtonPresentation } from \"./UserButtonPresentation.js\";\nimport type { BaseUser } from \"@/types.js\";\n\ninterface UserButtonProps {\n className?: string;\n style?: React.CSSProperties;\n onSignIn?: (user: BaseUser | undefined) => void;\n onSignOut?: () => void;\n clientId?: string;\n oauthServerBaseUrl?: string;\n baseUrl?: string;\n}\n\nconst ChevronDown = () => (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"lucide lucide-chevron-down\"\n >\n <path d=\"m6 9 6 6 6-6\" />\n </svg>\n);\n\nconst ChevronUp = () => (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"lucide lucide-chevron-up\"\n >\n <path d=\"m18 15-6-6-6 6\" />\n </svg>\n);\n\nexport function UserButton({\n className,\n style,\n onSignIn,\n onSignOut,\n}: UserButtonProps) {\n const { user, isLoggedIn, signIn, signOut } = useUser();\n const [isAuthenticating, setIsAuthenticating] = useState(false);\n const [isOpen, setIsOpen] = useState(false);\n const [buttonWidth, setButtonWidth] = useState<number | null>(null);\n const buttonRef = useRef<HTMLDivElement>(null);\n const dropdownRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (buttonRef.current) {\n setButtonWidth(buttonRef.current.offsetWidth);\n }\n }, [isOpen]);\n\n const handleClickOutside = useCallback((event: MouseEvent) => {\n const target = event.target as HTMLElement;\n if (\n buttonRef.current &&\n dropdownRef.current &&\n !buttonRef.current.contains(target) &&\n !dropdownRef.current.contains(target)\n ) {\n setIsOpen(false);\n }\n }, []);\n\n const handleEscape = useCallback((event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n setIsOpen(false);\n setIsAuthenticating(false);\n }\n }, []);\n\n useEffect(() => {\n if (isOpen) {\n window.addEventListener(\"click\", handleClickOutside);\n window.addEventListener(\"keydown\", handleEscape);\n }\n return () => {\n window.removeEventListener(\"click\", handleClickOutside);\n window.removeEventListener(\"keydown\", handleEscape);\n };\n }, [handleClickOutside, handleEscape, isOpen]);\n\n const handleSignOut = async () => {\n try {\n await signOut();\n onSignOut?.();\n } catch (error) {\n console.error(\"❌ Sign out error:\", error);\n } finally {\n setIsOpen(false);\n }\n };\n\n return (\n <>\n {/* Authentication modal overlay */}\n\n <div\n style={{ position: \"relative\", width: \"auto\" }}\n id=\"civic-dropdown-container\"\n >\n <div ref={buttonRef}>\n <UserButtonPresentation\n className={className}\n onClick={async () => {\n if (isLoggedIn) {\n setIsOpen(!isOpen);\n return;\n }\n\n const { user } = await signIn({ displayMode: \"iframe\" });\n onSignIn?.(user);\n }}\n data-testid=\"sign-in-button\"\n style={{\n ...style,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n gap: \"0.5rem\",\n minWidth: \"10rem\",\n cursor: isAuthenticating ? \"wait\" : \"pointer\",\n textAlign: \"center\",\n opacity: isAuthenticating ? 0.7 : 1,\n }}\n >\n {isLoggedIn ? (\n <>\n {user?.picture && (\n <span\n style={{\n position: \"relative\",\n display: \"flex\",\n height: \"1.5rem\",\n width: \"1.5rem\",\n flexShrink: 0,\n gap: \"0.5rem\",\n overflow: \"hidden\",\n borderRadius: \"9999px\",\n }}\n >\n <img\n style={{\n height: \"100%\",\n width: \"100%\",\n objectFit: \"cover\",\n }}\n src={user.picture}\n alt={user?.name || user?.email}\n />\n </span>\n )}\n <span>{user?.name || user?.email}</span>\n <span>{isOpen ? <ChevronUp /> : <ChevronDown />}</span>\n </>\n ) : (\n <span>{isAuthenticating ? \"Signing in...\" : \"Sign in\"}</span>\n )}\n </UserButtonPresentation>\n </div>\n {isLoggedIn && isOpen && (\n <div\n ref={dropdownRef}\n style={{\n position: \"absolute\",\n left: 0,\n background: \"white\",\n width: buttonWidth || \"auto\",\n marginTop: \"0.5rem\",\n borderRadius: \"0.5rem\",\n boxShadow:\n \"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)\",\n zIndex: 1000,\n }}\n >\n <ul style={{ listStyleType: \"none\", margin: 0, padding: 0 }}>\n <li>\n <button\n style={{\n display: \"block\",\n width: \"100%\",\n padding: \"0.5rem 1rem\",\n transition: \"background-color 0.2s\",\n textAlign: \"center\",\n color: \"#6b7280\",\n cursor: \"pointer\",\n borderRadius: \"0.5rem\",\n border: \"none\",\n background: \"transparent\",\n }}\n onClick={handleSignOut}\n >\n Logout\n </button>\n </li>\n </ul>\n </div>\n )}\n </div>\n </>\n );\n}\n"]}
@@ -0,0 +1,10 @@
1
+ interface UserButtonPresentationProps {
2
+ className?: string;
3
+ style?: React.CSSProperties;
4
+ onClick?: () => void;
5
+ "data-testid"?: string;
6
+ children: React.ReactNode;
7
+ }
8
+ export declare function UserButtonPresentation({ className, style, onClick, "data-testid": dataTestId, children, }: UserButtonPresentationProps): import("@emotion/react/jsx-runtime").JSX.Element;
9
+ export {};
10
+ //# sourceMappingURL=UserButtonPresentation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserButtonPresentation.d.ts","sourceRoot":"","sources":["../../../src/react-router-7/components/UserButtonPresentation.tsx"],"names":[],"mappings":"AAEA,UAAU,2BAA2B;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,wBAAgB,sBAAsB,CAAC,EACrC,SAAS,EACT,KAAK,EACL,OAAO,EACP,aAAa,EAAE,UAAU,EACzB,QAAQ,GACT,EAAE,2BAA2B,oDA0B7B"}
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
3
+ export function UserButtonPresentation({ className, style, onClick, "data-testid": dataTestId, children, }) {
4
+ return (_jsx("button", { className: className, style: {
5
+ cursor: "pointer",
6
+ borderRadius: "9999px",
7
+ border: "1px solid #6b7280",
8
+ padding: "0.75rem 1rem",
9
+ color: "#6b7280",
10
+ transition: "background-color 0.2s",
11
+ minWidth: "9em",
12
+ ...style,
13
+ }, onClick: onClick, "data-testid": dataTestId, onMouseEnter: (e) => {
14
+ e.currentTarget.style.backgroundColor = "#f3f4f6";
15
+ }, onMouseLeave: (e) => {
16
+ e.currentTarget.style.backgroundColor = "";
17
+ }, children: children }));
18
+ }
19
+ //# sourceMappingURL=UserButtonPresentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserButtonPresentation.js","sourceRoot":"","sources":["../../../src/react-router-7/components/UserButtonPresentation.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAUb,MAAM,UAAU,sBAAsB,CAAC,EACrC,SAAS,EACT,KAAK,EACL,OAAO,EACP,aAAa,EAAE,UAAU,EACzB,QAAQ,GACoB;IAC5B,OAAO,CACL,iBACE,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE;YACL,MAAM,EAAE,SAAS;YACjB,YAAY,EAAE,QAAQ;YACtB,MAAM,EAAE,mBAAmB;YAC3B,OAAO,EAAE,cAAc;YACvB,KAAK,EAAE,SAAS;YAChB,UAAU,EAAE,uBAAuB;YACnC,QAAQ,EAAE,KAAK;YACf,GAAG,KAAK;SACT,EACD,OAAO,EAAE,OAAO,iBACH,UAAU,EACvB,YAAY,EAAE,CAAC,CAAC,EAAE,EAAE;YAClB,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,eAAe,GAAG,SAAS,CAAC;QACpD,CAAC,EACD,YAAY,EAAE,CAAC,CAAC,EAAE,EAAE;YAClB,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC;QAC7C,CAAC,YAEA,QAAQ,GACF,CACV,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\ninterface UserButtonPresentationProps {\n className?: string;\n style?: React.CSSProperties;\n onClick?: () => void;\n \"data-testid\"?: string;\n children: React.ReactNode;\n}\n\nexport function UserButtonPresentation({\n className,\n style,\n onClick,\n \"data-testid\": dataTestId,\n children,\n}: UserButtonPresentationProps) {\n return (\n <button\n className={className}\n style={{\n cursor: \"pointer\",\n borderRadius: \"9999px\",\n border: \"1px solid #6b7280\",\n padding: \"0.75rem 1rem\",\n color: \"#6b7280\",\n transition: \"background-color 0.2s\",\n minWidth: \"9em\",\n ...style,\n }}\n onClick={onClick}\n data-testid={dataTestId}\n onMouseEnter={(e) => {\n e.currentTarget.style.backgroundColor = \"#f3f4f6\";\n }}\n onMouseLeave={(e) => {\n e.currentTarget.style.backgroundColor = \"\";\n }}\n >\n {children}\n </button>\n );\n}\n"]}
@@ -0,0 +1,69 @@
1
+ import type { UnknownObject } from "../types.js";
2
+ import { type ReactRouterCookiesConfigObject } from "../shared/lib/cookieConfig.js";
3
+ export type { ReactRouterCookiesConfigObject as CookiesConfigObject };
4
+ /**
5
+ * Simplified user-facing configuration for Civic Auth React Router 7 integration
6
+ */
7
+ export interface UserAuthConfig {
8
+ /** OAuth Client ID - Required */
9
+ clientId: string;
10
+ /** URL to redirect to after successful login - defaults to root of app */
11
+ loginSuccessUrl?: string;
12
+ /** OAuth Callback URL - defaults to /auth/callback */
13
+ callbackUrl?: string;
14
+ /** URL to redirect to after logout - defaults to / */
15
+ logoutUrl?: string;
16
+ /** The public-facing base URL for your application. Required when deploying behind reverse proxies */
17
+ baseUrl?: string;
18
+ }
19
+ /**
20
+ * Internal logging configuration for Civic Auth
21
+ */
22
+ export interface LoggingConfig {
23
+ /** Enable logging for these namespaces (e.g. "@civic/auth:*" or "@civic/auth:react-router:*") */
24
+ enableFor?: string;
25
+ /** Disable logging for these namespaces */
26
+ disableFor?: string;
27
+ }
28
+ /**
29
+ * Internal full configuration with all options
30
+ */
31
+ export interface AuthConfig extends UserAuthConfig {
32
+ /** OAuth Server URL */
33
+ oauthServer: string;
34
+ /** Login URL path */
35
+ loginUrl?: string;
36
+ /** Refresh token URL path */
37
+ refreshUrl?: string;
38
+ /** User data endpoint URL path */
39
+ userUrl?: string;
40
+ /** OAuth scope */
41
+ scope?: string;
42
+ /** Routes to include in authentication checks */
43
+ include?: string[];
44
+ /** Routes to exclude from authentication checks */
45
+ exclude?: string[];
46
+ /** Environment variable overrides */
47
+ env?: UnknownObject;
48
+ /** Logging configuration */
49
+ logging?: LoggingConfig;
50
+ }
51
+ export interface AuthConfigWithDefaults extends AuthConfig {
52
+ loginUrl: string;
53
+ logoutUrl: string;
54
+ refreshUrl: string;
55
+ userUrl: string;
56
+ logoutCallbackUrl: string;
57
+ scope: string;
58
+ include: string[];
59
+ exclude: string[];
60
+ cookies: ReactRouterCookiesConfigObject;
61
+ logging?: LoggingConfig;
62
+ }
63
+ export declare const defaultAuthConfig: Partial<AuthConfigWithDefaults>;
64
+ /**
65
+ * Creates a full internal configuration from simplified user config
66
+ */
67
+ export declare function createCivicAuthConfig(userConfig: UserAuthConfig): AuthConfigWithDefaults;
68
+ export declare function resolveAuthConfig(userConfig?: Partial<UserAuthConfig>): AuthConfigWithDefaults;
69
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/react-router-7/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,8BAA8B,CAAC;AAGtC,YAAY,EAAE,8BAA8B,IAAI,mBAAmB,EAAE,CAAC;AAItE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,iC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AC;IACxC,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAED,eAAO,MAAM,iBAAiB,EAAE,OAAO,CAAC,sBAAsB,CAQ7D,CAAC;AAIF;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,cAAc,GACzB,sBAAsB,CAoBxB;AAED,wBAAgB,iBAAiB,CAC/B,UAAU,GAAE,OAAO,CAAC,cAAc,CAAM,GACvC,sBAAsB,CA0DxB"}
@@ -0,0 +1,88 @@
1
+ import { loggers } from "../lib/logger.js";
2
+ import debug from "debug";
3
+ import { createReactRouterCookieConfig, } from "../shared/lib/cookieConfig.js";
4
+ const logger = loggers.reactRouter.handlers.auth;
5
+ export const defaultAuthConfig = {
6
+ // Backend route paths (these are the endpoints this React Router app provides)
7
+ loginUrl: "/auth/login",
8
+ scope: "openid profile email offline_access", // Added offline_access for refresh tokens
9
+ cookies: createReactRouterCookieConfig(),
10
+ logging: {
11
+ enableFor: undefined, // Logging off by default
12
+ },
13
+ };
14
+ let _resolvedConfig = null;
15
+ /**
16
+ * Creates a full internal configuration from simplified user config
17
+ */
18
+ export function createCivicAuthConfig(userConfig) {
19
+ const config = {
20
+ ...userConfig,
21
+ oauthServer: process.env.OAUTH_SERVER || "https://auth.civic.com/oauth",
22
+ };
23
+ return {
24
+ ...defaultAuthConfig,
25
+ ...config,
26
+ // Override callbackUrl default if user provided one
27
+ callbackUrl: userConfig.callbackUrl,
28
+ // Use logoutUrl from user config as logoutCallbackUrl
29
+ logoutCallbackUrl: userConfig.logoutUrl,
30
+ // Provide empty arrays for include/exclude if not specified
31
+ cookies: defaultAuthConfig.cookies, // Use default cookies, not user-configurable
32
+ logging: {
33
+ ...defaultAuthConfig.logging,
34
+ ...config.logging,
35
+ },
36
+ };
37
+ }
38
+ export function resolveAuthConfig(userConfig = {}) {
39
+ if (_resolvedConfig && Object.keys(userConfig).length === 0) {
40
+ return _resolvedConfig;
41
+ }
42
+ const mergedConfig = createCivicAuthConfig({
43
+ clientId: process.env.CLIENT_ID || userConfig.clientId || "",
44
+ ...userConfig,
45
+ });
46
+ logger.debug("Resolved config:", JSON.stringify(mergedConfig, null, 2));
47
+ if (!mergedConfig.clientId) {
48
+ logger.error("Civic Auth client ID is required");
49
+ throw new Error("Civic Auth client ID is required");
50
+ }
51
+ // Configure logging based on configuration
52
+ if (mergedConfig.logging) {
53
+ try {
54
+ if (mergedConfig.logging.enableFor) {
55
+ // Set the DEBUG environment variable
56
+ if (typeof process !== "undefined" && process.env) {
57
+ process.env.DEBUG = mergedConfig.logging.enableFor;
58
+ }
59
+ // Reset debug internal state and enable the specified namespaces
60
+ debug.disable();
61
+ debug.enable(mergedConfig.logging.enableFor);
62
+ logger.debug(`Logging enabled for: ${mergedConfig.logging.enableFor}`);
63
+ }
64
+ if (mergedConfig.logging.disableFor) {
65
+ // To disable specific namespaces while keeping others enabled, we need to
66
+ // update the DEBUG environment variable directly
67
+ if (process.env.DEBUG) {
68
+ const currentDebug = process.env.DEBUG;
69
+ const disablePattern = mergedConfig.logging.disableFor;
70
+ process.env.DEBUG = currentDebug
71
+ .split(",")
72
+ .filter((pattern) => pattern !== disablePattern)
73
+ .join(",");
74
+ // Reset debug internal state and re-enable with updated pattern
75
+ debug.disable();
76
+ debug.enable(process.env.DEBUG);
77
+ logger.debug(`Logging disabled for: ${disablePattern}`);
78
+ }
79
+ }
80
+ }
81
+ catch (e) {
82
+ logger.error("Failed to configure logging:", e);
83
+ }
84
+ }
85
+ _resolvedConfig = mergedConfig;
86
+ return mergedConfig;
87
+ }
88
+ //# sourceMappingURL=config.js.map