@civic/auth 0.4.1 → 0.4.2-beta.1
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.
- package/dist/nextjs/middleware.d.ts +2 -1
- package/dist/nextjs/middleware.d.ts.map +1 -1
- package/dist/nextjs/middleware.js +30 -4
- package/dist/nextjs/middleware.js.map +1 -1
- package/dist/shared/components/BlockDisplay.d.ts +2 -2
- package/dist/shared/components/BlockDisplay.d.ts.map +1 -1
- package/dist/shared/components/BlockDisplay.js +10 -8
- package/dist/shared/components/BlockDisplay.js.map +1 -1
- package/dist/shared/components/CivicAuthIframe.d.ts.map +1 -1
- package/dist/shared/components/CivicAuthIframe.js +12 -3
- package/dist/shared/components/CivicAuthIframe.js.map +1 -1
- package/dist/shared/components/CivicAuthIframeContainer.d.ts.map +1 -1
- package/dist/shared/components/CivicAuthIframeContainer.js +9 -4
- package/dist/shared/components/CivicAuthIframeContainer.js.map +1 -1
- package/dist/shared/components/CivicAuthLogoutIframeContainer.d.ts +1 -1
- package/dist/shared/components/CivicAuthLogoutIframeContainer.d.ts.map +1 -1
- package/dist/shared/components/CivicAuthLogoutIframeContainer.js +8 -2
- package/dist/shared/components/CivicAuthLogoutIframeContainer.js.map +1 -1
- package/dist/shared/lib/iframeUtils.d.ts +1 -1
- package/dist/shared/lib/iframeUtils.d.ts.map +1 -1
- package/dist/shared/lib/iframeUtils.js +1 -1
- package/dist/shared/lib/iframeUtils.js.map +1 -1
- package/dist/shared/version.d.ts +1 -1
- package/dist/shared/version.d.ts.map +1 -1
- package/dist/shared/version.js +1 -1
- package/dist/shared/version.js.map +1 -1
- package/package.json +4 -4
|
@@ -27,9 +27,10 @@ type Middleware = (request: NextRequest) => Promise<NextResponse> | NextResponse
|
|
|
27
27
|
* use a ServerAuthenticationResolver to validate the existing session
|
|
28
28
|
* using NextJS cookie storage
|
|
29
29
|
* @param authConfigWithDefaults
|
|
30
|
+
* @param request NextRequest object from middleware
|
|
30
31
|
* @returns {Promise<boolean>}
|
|
31
32
|
*/
|
|
32
|
-
export declare const validateAuthTokensIfPresent: (authConfigWithDefaults: AuthConfigWithDefaults) => Promise<boolean>;
|
|
33
|
+
export declare const validateAuthTokensIfPresent: (authConfigWithDefaults: AuthConfigWithDefaults, request: NextRequest) => Promise<boolean>;
|
|
33
34
|
/**
|
|
34
35
|
*
|
|
35
36
|
* Use this when auth is the only middleware you need.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/nextjs/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,KAAK,EACV,sBAAsB,EACtB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/nextjs/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,KAAK,EACV,sBAAsB,EACtB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAmC5B,KAAK,UAAU,GAAG,CAChB,OAAO,EAAE,WAAW,KACjB,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC;AAuB1C;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,GACtC,wBAAwB,sBAAsB,EAC9C,SAAS,WAAW,KACnB,OAAO,CAAC,OAAO,CAkBjB,CAAC;AA+CF;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GACxB,aAAY,kBAAuB,MAC7B,SAAS,WAAW,KAAG,OAAO,CAAC,YAAY,CAOjD,CAAC;AAEJ;;;;;;;GAOG;AAEH,wBAAgB,QAAQ,CACtB,UAAU,EAAE,UAAU,GACrB,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,CAEjD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,IAAI,CAAC,UAAU,GAAE,kBAAuB,IAEpD,YAAY,UAAU,KACrB,CAAC,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC,CAQrD"}
|
|
@@ -3,8 +3,33 @@ import picomatch from "picomatch";
|
|
|
3
3
|
import { resolveAuthConfig } from "../nextjs/config.js";
|
|
4
4
|
import { loggers } from "../lib/logger.js";
|
|
5
5
|
import { ServerAuthenticationResolver } from "../server/ServerAuthenticationResolver.js";
|
|
6
|
-
import { NextjsCookieStorage } from "./cookies.js";
|
|
7
6
|
const logger = loggers.nextjs.middleware;
|
|
7
|
+
/**
|
|
8
|
+
* CookieStorage implementation for NextJS middleware context that works with NextRequest
|
|
9
|
+
*/
|
|
10
|
+
class NextjsReadOnlyRequestCookieStorage {
|
|
11
|
+
request;
|
|
12
|
+
constructor(request) {
|
|
13
|
+
this.request = request;
|
|
14
|
+
}
|
|
15
|
+
async get(key) {
|
|
16
|
+
return this.request.cookies.get(key)?.value || null;
|
|
17
|
+
}
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
|
+
async set(key, value) {
|
|
20
|
+
// In middleware, we can only set cookies via response objects
|
|
21
|
+
// This method can't be used directly in middleware
|
|
22
|
+
logger.error("Cannot set cookies directly in middleware");
|
|
23
|
+
throw new Error("Cannot set cookies directly in middleware");
|
|
24
|
+
}
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
26
|
+
async delete(key) {
|
|
27
|
+
// In middleware, we can only delete cookies via response objects
|
|
28
|
+
// This method can't be used directly in middleware
|
|
29
|
+
logger.error("Cannot delete cookies directly in middleware");
|
|
30
|
+
throw new Error("Cannot delete cookies directly in middleware");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
8
33
|
// Matches globs:
|
|
9
34
|
// Examples:
|
|
10
35
|
// /user
|
|
@@ -28,13 +53,14 @@ const matchesGlobs = (pathname, patterns) => patterns.some((pattern) => {
|
|
|
28
53
|
* use a ServerAuthenticationResolver to validate the existing session
|
|
29
54
|
* using NextJS cookie storage
|
|
30
55
|
* @param authConfigWithDefaults
|
|
56
|
+
* @param request NextRequest object from middleware
|
|
31
57
|
* @returns {Promise<boolean>}
|
|
32
58
|
*/
|
|
33
|
-
export const validateAuthTokensIfPresent = async (authConfigWithDefaults) => {
|
|
59
|
+
export const validateAuthTokensIfPresent = async (authConfigWithDefaults, request) => {
|
|
34
60
|
try {
|
|
35
61
|
// TODO: evaluate a more performant way to validate tokens
|
|
36
62
|
// than having to call and verify the JWT tokens on every request
|
|
37
|
-
const storage = new
|
|
63
|
+
const storage = new NextjsReadOnlyRequestCookieStorage(request);
|
|
38
64
|
const authSessionService = await ServerAuthenticationResolver.build({
|
|
39
65
|
...authConfigWithDefaults,
|
|
40
66
|
redirectUrl: authConfigWithDefaults.callbackUrl,
|
|
@@ -51,7 +77,7 @@ export const validateAuthTokensIfPresent = async (authConfigWithDefaults) => {
|
|
|
51
77
|
const applyAuth = async (authConfig, request) => {
|
|
52
78
|
const authConfigWithDefaults = resolveAuthConfig(authConfig);
|
|
53
79
|
// Check for any valid auth token
|
|
54
|
-
const isAuthenticated = await validateAuthTokensIfPresent(authConfigWithDefaults);
|
|
80
|
+
const isAuthenticated = await validateAuthTokensIfPresent(authConfigWithDefaults, request);
|
|
55
81
|
// skip auth check for redirect to login url
|
|
56
82
|
if (request.nextUrl.pathname === authConfigWithDefaults.loginUrl &&
|
|
57
83
|
request.method === "GET") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/nextjs/middleware.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC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AAC;QACF,MAAM,WAAW,GAAG,GAAG,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC;QAC7C,MAAM,CAAC,KAAK,CAAC,4CAA4C,WAAW,GAAG,CAAC,CAAC;QACzE,OAAO,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACpC,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,CAAC,aAAiC,EAAE,EAAE,EAAE,CACxC,KAAK,EAAE,OAAoB,EAAyB,EAAE;IACpD,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACtD,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAE9B,mEAAmE;IACnE,wEAAwE;IACxE,OAAO,YAAY,CAAC,IAAI,EAAE,CAAC;AAC7B,CAAC,CAAC;AAEJ;;;;;;;GAOG;AACH,sDAAsD;AACtD,MAAM,UAAU,QAAQ,CACtB,UAAsB;IAEtB,OAAO,IAAI,EAAE,CAAC,UAAU,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,IAAI,CAAC,aAAiC,EAAE;IACtD,OAAO,CACL,UAAsB,EAC6B,EAAE;QACrD,OAAO,KAAK,EAAE,OAAoB,EAAyB,EAAE;YAC3D,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YACtD,IAAI,QAAQ;gBAAE,OAAO,QAAQ,CAAC;YAE9B,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Authenticates the user on all requests by checking the token cookie\n *\n * Usage:\n * Option 1: use if no other middleware (e.g. no next-intl etc)\n * export default authMiddleware();\n *\n * Option 2: use if other middleware is needed - default auth config\n * export default withAuth((request) => {\n * logger.debug('in custom middleware', request.nextUrl.pathname);\n * return NextResponse.next();\n * })\n *\n * Option 3: use if other middleware is needed - specifying auth config\n * const withCivicAuth = auth({ loginUrl: '/login', include: ['/[.*]/user'] })\n * export default withCivicAuth((request) => {\n * logger.debug('in custom middleware', request.url);\n * return NextResponse.next();\n * })\n *\n */\nimport type { NextRequest } from \"next/server.js\";\nimport { NextResponse } from \"next/server.js\";\nimport picomatch from \"picomatch\";\nimport type {\n AuthConfigWithDefaults,\n OptionalAuthConfig,\n} from \"@/nextjs/config.js\";\nimport { resolveAuthConfig } from \"@/nextjs/config.js\";\nimport { loggers } from \"@/lib/logger.js\";\nimport { ServerAuthenticationResolver } from \"@/server/ServerAuthenticationResolver.js\";\nimport { NextjsCookieStorage } from \"./cookies.js\";\n\nconst logger = loggers.nextjs.middleware;\n\ntype Middleware = (\n request: NextRequest,\n) => Promise<NextResponse> | NextResponse;\n\n// Matches globs:\n// Examples:\n// /user\n// /user/*\n// /user/**/info\nconst matchGlob = (pathname: string, globPattern: string) => {\n const matches = picomatch(globPattern);\n return matches(pathname);\n};\n\n// Matches globs:\n// Examples:\n// /user\n// /user/*\n// /user/**/info\nconst matchesGlobs = (pathname: string, patterns: string[]) =>\n patterns.some((pattern) => {\n if (!pattern) return false;\n return matchGlob(pathname, pattern);\n });\n\n/**\n * use a ServerAuthenticationResolver to validate the existing session\n * using NextJS cookie storage\n * @param authConfigWithDefaults\n * @returns {Promise<boolean>}\n */\nexport const validateAuthTokensIfPresent = async (\n authConfigWithDefaults: AuthConfigWithDefaults,\n): Promise<boolean> => {\n try {\n // TODO: evaluate a more performant way to validate tokens\n // than having to call and verify the JWT tokens on every request\n const storage = new NextjsCookieStorage(authConfigWithDefaults.cookies);\n const authSessionService = await ServerAuthenticationResolver.build(\n {\n ...authConfigWithDefaults,\n redirectUrl: authConfigWithDefaults.callbackUrl,\n },\n storage,\n );\n const existingSession = await authSessionService.validateExistingSession();\n return existingSession.authenticated;\n } catch (error) {\n logger.error(\"Error validating tokens\", error);\n return false;\n }\n};\n// internal - used by all exported functions\nconst applyAuth = async (\n authConfig: OptionalAuthConfig,\n request: NextRequest,\n): Promise<NextResponse | undefined> => {\n const authConfigWithDefaults = resolveAuthConfig(authConfig);\n // Check for any valid auth token\n const isAuthenticated = await validateAuthTokensIfPresent(\n authConfigWithDefaults,\n );\n\n // skip auth check for redirect to login url\n if (\n request.nextUrl.pathname === authConfigWithDefaults.loginUrl &&\n request.method === \"GET\"\n ) {\n logger.debug(\"→ Skipping auth check - this is the login URL\");\n return undefined;\n }\n\n if (!matchesGlobs(request.nextUrl.pathname, authConfigWithDefaults.include)) {\n logger.debug(\"→ Skipping auth check - path not in include patterns\");\n return undefined;\n }\n\n if (matchesGlobs(request.nextUrl.pathname, authConfigWithDefaults.exclude)) {\n logger.debug(\"→ Skipping auth check - path in exclude patterns\");\n return undefined;\n }\n\n // Check for either token type\n if (!isAuthenticated) {\n const loginUrl = new URL(\n authConfigWithDefaults.loginUrl,\n request.nextUrl.origin,\n );\n const redirectUrl = `${loginUrl.toString()}`;\n logger.debug(`→ No valid token found - redirecting to \"${redirectUrl}\"`);\n return NextResponse.redirect(redirectUrl);\n }\n\n logger.debug(\"→ Auth check passed\");\n return undefined;\n};\n\n/**\n *\n * Use this when auth is the only middleware you need.\n * Usage:\n *\n * export default authMiddleware({ loginUrl = '/login' }); // or just authMiddleware();\n *\n */\nexport const authMiddleware =\n (authConfig: OptionalAuthConfig = {}) =>\n async (request: NextRequest): Promise<NextResponse> => {\n const response = await applyAuth(authConfig, request);\n if (response) return response;\n\n // NextJS doesn't do middleware chaining yet, so this does not mean\n // \"call the next middleware\" - it means \"continue to the route handler\"\n return NextResponse.next();\n };\n\n/**\n * Usage:\n *\n * export default withAuth(async (request) => {\n * logger.debug('my middleware');\n * return NextResponse.next();\n * })\n */\n// use this when you have your own middleware to chain\nexport function withAuth(\n middleware: Middleware,\n): (request: NextRequest) => Promise<NextResponse> {\n return auth()(middleware);\n}\n\n/**\n * Use this when you want to configure the middleware here (an alternative is to do it in the next.config file)\n *\n * Usage:\n *\n * export default auth(authConfig: AuthConfig ) => {\n * logger.debug('my middleware');\n * return NextResponse.next();\n * })\n *\n */\nexport function auth(authConfig: OptionalAuthConfig = {}) {\n return (\n middleware: Middleware,\n ): ((request: NextRequest) => Promise<NextResponse>) => {\n return async (request: NextRequest): Promise<NextResponse> => {\n const response = await applyAuth(authConfig, request);\n if (response) return response;\n\n return middleware(request);\n };\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/nextjs/middleware.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,SAAS,MAAM,WAAW,CAAC;AAKlC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,4BAA4B,EAAE,MAAM,0CAA0C,CAAC;AAGxF,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;AAEzC;;GAEG;AACH,MAAM,kCAAkC;IAClB;IAApB,YAAoB,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IAAG,CAAC;IAE5C,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,IAAI,IAAI,CAAC;IACtD,CAAC;IAED,6DAA6D;IAC7D,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAa;QAClC,8DAA8D;QAC9D,mDAAmD;QACnD,MAAM,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IAED,6DAA6D;IAC7D,KAAK,CAAC,MAAM,C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OAAO,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACpC,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,CAAC,aAAiC,EAAE,EAAE,EAAE,CACxC,KAAK,EAAE,OAAoB,EAAyB,EAAE;IACpD,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACtD,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAE9B,mEAAmE;IACnE,wEAAwE;IACxE,OAAO,YAAY,CAAC,IAAI,EAAE,CAAC;AAC7B,CAAC,CAAC;AAEJ;;;;;;;GAOG;AACH,sDAAsD;AACtD,MAAM,UAAU,QAAQ,CACtB,UAAsB;IAEtB,OAAO,IAAI,EAAE,CAAC,UAAU,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,IAAI,CAAC,aAAiC,EAAE;IACtD,OAAO,CACL,UAAsB,EAC6B,EAAE;QACrD,OAAO,KAAK,EAAE,OAAoB,EAAyB,EAAE;YAC3D,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YACtD,IAAI,QAAQ;gBAAE,OAAO,QAAQ,CAAC;YAE9B,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Authenticates the user on all requests by checking the token cookie\n *\n * Usage:\n * Option 1: use if no other middleware (e.g. no next-intl etc)\n * export default authMiddleware();\n *\n * Option 2: use if other middleware is needed - default auth config\n * export default withAuth((request) => {\n * logger.debug('in custom middleware', request.nextUrl.pathname);\n * return NextResponse.next();\n * })\n *\n * Option 3: use if other middleware is needed - specifying auth config\n * const withCivicAuth = auth({ loginUrl: '/login', include: ['/[.*]/user'] })\n * export default withCivicAuth((request) => {\n * logger.debug('in custom middleware', request.url);\n * return NextResponse.next();\n * })\n *\n */\nimport type { NextRequest } from \"next/server.js\";\nimport { NextResponse } from \"next/server.js\";\nimport picomatch from \"picomatch\";\nimport type {\n AuthConfigWithDefaults,\n OptionalAuthConfig,\n} from \"@/nextjs/config.js\";\nimport { resolveAuthConfig } from \"@/nextjs/config.js\";\nimport { loggers } from \"@/lib/logger.js\";\nimport { ServerAuthenticationResolver } from \"@/server/ServerAuthenticationResolver.js\";\nimport type { AuthStorage } from \"@/types.js\";\n\nconst logger = loggers.nextjs.middleware;\n\n/**\n * CookieStorage implementation for NextJS middleware context that works with NextRequest\n */\nclass NextjsReadOnlyRequestCookieStorage implements AuthStorage {\n constructor(private request: NextRequest) {}\n\n async get(key: string): Promise<string | null> {\n return this.request.cookies.get(key)?.value || null;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async set(key: string, value: string): Promise<void> {\n // In middleware, we can only set cookies via response objects\n // This method can't be used directly in middleware\n logger.error(\"Cannot set cookies directly in middleware\");\n throw new Error(\"Cannot set cookies directly in middleware\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async delete(key: string): Promise<void> {\n // In middleware, we can only delete cookies via response objects\n // This method can't be used directly in middleware\n logger.error(\"Cannot delete cookies directly in middleware\");\n throw new Error(\"Cannot delete cookies directly in middleware\");\n }\n}\n\ntype Middleware = (\n request: NextRequest,\n) => Promise<NextResponse> | NextResponse;\n\n// Matches globs:\n// Examples:\n// /user\n// /user/*\n// /user/**/info\nconst matchGlob = (pathname: string, globPattern: string) => {\n const matches = picomatch(globPattern);\n return matches(pathname);\n};\n\n// Matches globs:\n// Examples:\n// /user\n// /user/*\n// /user/**/info\nconst matchesGlobs = (pathname: string, patterns: string[]) =>\n patterns.some((pattern) => {\n if (!pattern) return false;\n return matchGlob(pathname, pattern);\n });\n\n/**\n * use a ServerAuthenticationResolver to validate the existing session\n * using NextJS cookie storage\n * @param authConfigWithDefaults\n * @param request NextRequest object from middleware\n * @returns {Promise<boolean>}\n */\nexport const validateAuthTokensIfPresent = async (\n authConfigWithDefaults: AuthConfigWithDefaults,\n request: NextRequest,\n): Promise<boolean> => {\n try {\n // TODO: evaluate a more performant way to validate tokens\n // than having to call and verify the JWT tokens on every request\n const storage = new NextjsReadOnlyRequestCookieStorage(request);\n const authSessionService = await ServerAuthenticationResolver.build(\n {\n ...authConfigWithDefaults,\n redirectUrl: authConfigWithDefaults.callbackUrl,\n },\n storage,\n );\n const existingSession = await authSessionService.validateExistingSession();\n return existingSession.authenticated;\n } catch (error) {\n logger.error(\"Error validating tokens\", error);\n return false;\n }\n};\n// internal - used by all exported functions\nconst applyAuth = async (\n authConfig: OptionalAuthConfig,\n request: NextRequest,\n): Promise<NextResponse | undefined> => {\n const authConfigWithDefaults = resolveAuthConfig(authConfig);\n // Check for any valid auth token\n const isAuthenticated = await validateAuthTokensIfPresent(\n authConfigWithDefaults,\n request,\n );\n\n // skip auth check for redirect to login url\n if (\n request.nextUrl.pathname === authConfigWithDefaults.loginUrl &&\n request.method === \"GET\"\n ) {\n logger.debug(\"→ Skipping auth check - this is the login URL\");\n return undefined;\n }\n\n if (!matchesGlobs(request.nextUrl.pathname, authConfigWithDefaults.include)) {\n logger.debug(\"→ Skipping auth check - path not in include patterns\");\n return undefined;\n }\n\n if (matchesGlobs(request.nextUrl.pathname, authConfigWithDefaults.exclude)) {\n logger.debug(\"→ Skipping auth check - path in exclude patterns\");\n return undefined;\n }\n\n // Check for either token type\n if (!isAuthenticated) {\n const loginUrl = new URL(\n authConfigWithDefaults.loginUrl,\n request.nextUrl.origin,\n );\n const redirectUrl = `${loginUrl.toString()}`;\n logger.debug(`→ No valid token found - redirecting to \"${redirectUrl}\"`);\n return NextResponse.redirect(redirectUrl);\n }\n\n logger.debug(\"→ Auth check passed\");\n return undefined;\n};\n\n/**\n *\n * Use this when auth is the only middleware you need.\n * Usage:\n *\n * export default authMiddleware({ loginUrl = '/login' }); // or just authMiddleware();\n *\n */\nexport const authMiddleware =\n (authConfig: OptionalAuthConfig = {}) =>\n async (request: NextRequest): Promise<NextResponse> => {\n const response = await applyAuth(authConfig, request);\n if (response) return response;\n\n // NextJS doesn't do middleware chaining yet, so this does not mean\n // \"call the next middleware\" - it means \"continue to the route handler\"\n return NextResponse.next();\n };\n\n/**\n * Usage:\n *\n * export default withAuth(async (request) => {\n * logger.debug('my middleware');\n * return NextResponse.next();\n * })\n */\n// use this when you have your own middleware to chain\nexport function withAuth(\n middleware: Middleware,\n): (request: NextRequest) => Promise<NextResponse> {\n return auth()(middleware);\n}\n\n/**\n * Use this when you want to configure the middleware here (an alternative is to do it in the next.config file)\n *\n * Usage:\n *\n * export default auth(authConfig: AuthConfig ) => {\n * logger.debug('my middleware');\n * return NextResponse.next();\n * })\n *\n */\nexport function auth(authConfig: OptionalAuthConfig = {}) {\n return (\n middleware: Middleware,\n ): ((request: NextRequest) => Promise<NextResponse>) => {\n return async (request: NextRequest): Promise<NextResponse> => {\n const response = await applyAuth(authConfig, request);\n if (response) return response;\n\n return middleware(request);\n };\n };\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
2
|
declare const BlockDisplay: ({ children }: {
|
|
3
3
|
children: ReactNode;
|
|
4
|
-
}) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
4
|
+
}) => import("@emotion/react/jsx-runtime").JSX.Element | null;
|
|
5
5
|
export { BlockDisplay };
|
|
6
6
|
//# sourceMappingURL=BlockDisplay.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockDisplay.d.ts","sourceRoot":"","sources":["../../../src/shared/components/BlockDisplay.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"BlockDisplay.d.ts","sourceRoot":"","sources":["../../../src/shared/components/BlockDisplay.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,QAAA,MAAM,YAAY,GAAI,cAAc;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,4DAsC1D,CAAC;AACF,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { useIsInIframe } from "../hooks/useIsInIframe.js";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
4
3
|
const BlockDisplay = ({ children }) => {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const [isClient, setIsClient] = useState(false);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
// only runs on client
|
|
7
|
+
setIsClient(true);
|
|
8
|
+
}, []);
|
|
9
|
+
// don't render in server-mode as the appearance changes after load
|
|
10
|
+
return !isClient ? null : (_jsx("div", { id: "iframe-block-display-wrapper", style: {
|
|
9
11
|
position: "relative",
|
|
10
12
|
left: 0,
|
|
11
13
|
top: 0,
|
|
@@ -15,14 +17,14 @@ const BlockDisplay = ({ children }) => {
|
|
|
15
17
|
width: "100vw",
|
|
16
18
|
alignItems: "center",
|
|
17
19
|
justifyContent: "center",
|
|
18
|
-
backgroundColor:
|
|
20
|
+
backgroundColor: "transparent",
|
|
19
21
|
}, children: _jsx("div", { id: "iframe-block-display", style: {
|
|
20
22
|
position: "absolute",
|
|
21
23
|
inset: 0,
|
|
22
24
|
display: "flex",
|
|
23
25
|
alignItems: "center",
|
|
24
26
|
justifyContent: "center",
|
|
25
|
-
backgroundColor:
|
|
27
|
+
backgroundColor: "transparent",
|
|
26
28
|
}, children: children }) }));
|
|
27
29
|
};
|
|
28
30
|
export { BlockDisplay };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockDisplay.js","sourceRoot":"","sources":["../../../src/shared/components/BlockDisplay.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"BlockDisplay.js","sourceRoot":"","sources":["../../../src/shared/components/BlockDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAE5D,MAAM,YAAY,GAAG,CAAC,EAAE,QAAQ,EAA2B,EAAE,EAAE;IAC7D,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChD,SAAS,CAAC,GAAG,EAAE;QACb,sBAAsB;QACtB,WAAW,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,mEAAmE;IACnE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACxB,cACE,EAAE,EAAC,8BAA8B,EACjC,KAAK,EAAE;YACL,QAAQ,EAAE,UAAU;YACpB,IAAI,EAAE,CAAC;YACP,GAAG,EAAE,CAAC;YACN,MAAM,EAAE,EAAE;YACV,OAAO,EAAE,MAAM;YACf,MAAM,EAAE,OAAO;YACf,KAAK,EAAE,OAAO;YACd,UAAU,EAAE,QAAQ;YACpB,cAAc,EAAE,QAAQ;YACxB,eAAe,EAAE,aAAa;SAC/B,YAED,cACE,EAAE,EAAC,sBAAsB,EACzB,KAAK,EAAE;gBACL,QAAQ,EAAE,UAAU;gBACpB,KAAK,EAAE,CAAC;gBACR,OAAO,EAAE,MAAM;gBACf,UAAU,EAAE,QAAQ;gBACpB,cAAc,EAAE,QAAQ;gBACxB,eAAe,EAAE,aAAa;aAC/B,YAEA,QAAQ,GACL,GACF,CACP,CAAC;AACJ,CAAC,CAAC;AACF,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { useEffect, useState, type ReactNode } from \"react\";\n\nconst BlockDisplay = ({ children }: { children: ReactNode }) => {\n const [isClient, setIsClient] = useState(false);\n useEffect(() => {\n // only runs on client\n setIsClient(true);\n }, []);\n // don't render in server-mode as the appearance changes after load\n return !isClient ? null : (\n <div\n id=\"iframe-block-display-wrapper\"\n style={{\n position: \"relative\",\n left: 0,\n top: 0,\n zIndex: 50,\n display: \"flex\",\n height: \"100vh\",\n width: \"100vw\",\n alignItems: \"center\",\n justifyContent: \"center\",\n backgroundColor: \"transparent\",\n }}\n >\n <div\n id=\"iframe-block-display\"\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n backgroundColor: \"transparent\",\n }}\n >\n {children}\n </div>\n </div>\n );\n};\nexport { BlockDisplay };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CivicAuthIframe.d.ts","sourceRoot":"","sources":["../../../src/shared/components/CivicAuthIframe.tsx"],"names":[],"mappings":"AACA,OAAO,KAA0C,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"CivicAuthIframe.d.ts","sourceRoot":"","sources":["../../../src/shared/components/CivicAuthIframe.tsx"],"names":[],"mappings":"AACA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAM/D,KAAK,oBAAoB,GAAG;IAC1B,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,QAAA,MAAM,eAAe,gGAqDpB,CAAC;AAIF,YAAY,EAAE,oBAAoB,EAAE,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
3
3
|
import React, { forwardRef, useEffect, useState } from "react";
|
|
4
|
-
import IframeResizer from "@iframe-resizer/react";
|
|
4
|
+
// import IframeResizer from "@iframe-resizer/react";
|
|
5
|
+
import IframeResizer from "iframe-resizer-react";
|
|
5
6
|
import SVGLoading from "./SVGLoading.js";
|
|
6
7
|
import { useIframe } from "../hooks/useIframe.js";
|
|
7
8
|
const CivicAuthIframe = forwardRef(({ onLoad, id }, ref) => {
|
|
@@ -13,7 +14,11 @@ const CivicAuthIframe = forwardRef(({ onLoad, id }, ref) => {
|
|
|
13
14
|
setIsClient(true);
|
|
14
15
|
}, []);
|
|
15
16
|
// don't render on the server as the appearance changes when the iframe is loaded from login-app post-messages
|
|
16
|
-
return !isClient ? null : (_jsxs("div", { children: [isLoaded ? null : (_jsx("span", { "data-testid": "iframe-shimmer-loader", children: iframeMode !== "embedded" && (_jsx(SVGLoading, { backgroundColor: backgroundColor })) })), _jsx(IframeResizer, { inPageLinks: true,
|
|
17
|
+
return !isClient ? null : (_jsxs("div", { children: [isLoaded ? null : (_jsx("span", { "data-testid": "iframe-shimmer-loader", children: iframeMode !== "embedded" && (_jsx(SVGLoading, { backgroundColor: backgroundColor })) })), _jsx(IframeResizer, { inPageLinks: true,
|
|
18
|
+
// iframe-resizer-react was downgraded due to a bug in the latest version
|
|
19
|
+
// the license field is not valid for the downgraded version
|
|
20
|
+
// license="1jy4dww5qzv-s54r73oxcn-v59f4kfgfz"
|
|
21
|
+
id: id, forwardRef: ref, "data-testid": "civic-auth-iframe-with-resizer", style: {
|
|
17
22
|
// we don't want the letterbox effect in embedded mode
|
|
18
23
|
height: iframeMode !== "embedded" ? "26px" : "24rem",
|
|
19
24
|
width: "100%",
|
|
@@ -26,7 +31,11 @@ const CivicAuthIframe = forwardRef(({ onLoad, id }, ref) => {
|
|
|
26
31
|
}, checkOrigin: false, onLoad: () => {
|
|
27
32
|
setIsLoaded(true);
|
|
28
33
|
onLoad?.();
|
|
29
|
-
}, allow: "camera; screen-wake-lock", allowFullScreen: true,
|
|
34
|
+
}, allow: "camera; screen-wake-lock", allowFullScreen: true,
|
|
35
|
+
// iframe-resizer-react was downgraded due to a bug in the latest version
|
|
36
|
+
// direction="vertical"
|
|
37
|
+
// the 'direction' field is not valid for the downgraded version
|
|
38
|
+
warningTimeout: 0 })] }));
|
|
30
39
|
});
|
|
31
40
|
CivicAuthIframe.displayName = "CivicAuthIframe";
|
|
32
41
|
export { CivicAuthIframe };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CivicAuthIframe.js","sourceRoot":"","sources":["../../../src/shared/components/CivicAuthIframe.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC/D,OAAO,aAAa,MAAM,
|
|
1
|
+
{"version":3,"file":"CivicAuthIframe.js","sourceRoot":"","sources":["../../../src/shared/components/CivicAuthIframe.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC/D,qDAAqD;AACrD,OAAO,aAAa,MAAM,sBAAsB,CAAC;AACjD,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAOlD,MAAM,eAAe,GAAG,UAAU,CAChC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE;IACtB,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACtD,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,SAAS,EAAE,CAAC;IACpD,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChD,SAAS,CAAC,GAAG,EAAE;QACb,sBAAsB;QACtB,WAAW,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,8GAA8G;IAC9G,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACxB,0BACG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACjB,8BAAkB,uBAAuB,YACtC,UAAU,KAAK,UAAU,IAAI,CAC5B,KAAC,UAAU,IAAC,eAAe,EAAE,eAAe,GAAI,CACjD,GACI,CACR,EACD,KAAC,aAAa,IACZ,WAAW;gBACX,yEAAyE;gBACzE,4DAA4D;gBAC5D,8CAA8C;gBAC9C,EAAE,EAAE,EAAE,EACN,UAAU,EAAE,GAAG,iBACF,gCAAgC,EAC7C,KAAK,EAAE;oBACL,sDAAsD;oBACtD,MAAM,EAAE,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;oBACpD,KAAK,EAAE,MAAM;oBACb,MAAM,EAAE,MAAM;oBACd,QAAQ,EAAE,MAAM;oBAChB,eAAe;oBACf,UAAU,EAAE,mBAAmB;oBAC/B,aAAa,EAAE,MAAM;oBACrB,YAAY,EAAE,MAAM;iBACrB,EACD,WAAW,EAAE,KAAK,EAClB,MAAM,EAAE,GAAG,EAAE;oBACX,WAAW,CAAC,IAAI,CAAC,CAAC;oBAClB,MAAM,EAAE,EAAE,CAAC;gBACb,CAAC,EACD,KAAK,EAAC,0BAA0B,EAChC,eAAe;gBACf,yEAAyE;gBACzE,uBAAuB;gBACvB,gEAAgE;gBAChE,cAAc,EAAE,CAAC,GACjB,IACE,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,CAAC,WAAW,GAAG,iBAAiB,CAAC;AAIhD,OAAO,EAAE,eAAe,EAAE,CAAC","sourcesContent":["\"use client\";\nimport React, { forwardRef, useEffect, useState } from \"react\";\n// import IframeResizer from \"@iframe-resizer/react\";\nimport IframeResizer from \"iframe-resizer-react\";\nimport SVGLoading from \"./SVGLoading.js\";\nimport { useIframe } from \"../hooks/useIframe.js\";\n\ntype CivicAuthIframeProps = {\n onLoad?: () => void;\n id: string;\n};\n\nconst CivicAuthIframe = forwardRef<HTMLIFrameElement, CivicAuthIframeProps>(\n ({ onLoad, id }, ref) => {\n const [isLoaded, setIsLoaded] = React.useState(false);\n const { iframeMode, backgroundColor } = useIframe();\n const [isClient, setIsClient] = useState(false);\n useEffect(() => {\n // only runs on client\n setIsClient(true);\n }, []);\n // don't render on the server as the appearance changes when the iframe is loaded from login-app post-messages\n return !isClient ? null : (\n <div>\n {isLoaded ? null : (\n <span data-testid=\"iframe-shimmer-loader\">\n {iframeMode !== \"embedded\" && (\n <SVGLoading backgroundColor={backgroundColor} />\n )}\n </span>\n )}\n <IframeResizer\n inPageLinks\n // iframe-resizer-react was downgraded due to a bug in the latest version\n // the license field is not valid for the downgraded version\n // license=\"1jy4dww5qzv-s54r73oxcn-v59f4kfgfz\"\n id={id}\n forwardRef={ref}\n data-testid={\"civic-auth-iframe-with-resizer\"}\n style={{\n // we don't want the letterbox effect in embedded mode\n height: iframeMode !== \"embedded\" ? \"26px\" : \"24rem\",\n width: \"100%\",\n border: \"none\",\n minWidth: \"100%\",\n backgroundColor,\n transition: \"height 0.25s ease\",\n pointerEvents: \"auto\",\n borderRadius: \"24px\",\n }}\n checkOrigin={false}\n onLoad={() => {\n setIsLoaded(true);\n onLoad?.();\n }}\n allow=\"camera; screen-wake-lock\"\n allowFullScreen\n // iframe-resizer-react was downgraded due to a bug in the latest version\n // direction=\"vertical\"\n // the 'direction' field is not valid for the downgraded version\n warningTimeout={0}\n />\n </div>\n );\n },\n);\n\nCivicAuthIframe.displayName = \"CivicAuthIframe\";\n\nexport type { CivicAuthIframeProps };\n\nexport { CivicAuthIframe };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CivicAuthIframeContainer.d.ts","sourceRoot":"","sources":["../../../src/shared/components/CivicAuthIframeContainer.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAUxE,KAAK,6BAA6B,GAAG;IACnC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAeF,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,OAAO,EACP,aAAa,GACd,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;CACxB,
|
|
1
|
+
{"version":3,"file":"CivicAuthIframeContainer.d.ts","sourceRoot":"","sources":["../../../src/shared/components/CivicAuthIframeContainer.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAUxE,KAAK,6BAA6B,GAAG;IACnC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAeF,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,OAAO,EACP,aAAa,GACd,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;CACxB,oDAiFA;AAED,QAAA,MAAM,wBAAwB,GAAI,+BAG/B,6BAA6B,qDAuH/B,CAAC;AAEF,YAAY,EAAE,6BAA6B,EAAE,CAAC;AAE9C,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -13,7 +13,7 @@ function NoChrome({ children, }) {
|
|
|
13
13
|
return (_jsx("div", { "data-testid": "civic-iframe-no-chrome", style: { position: "relative" }, children: children }));
|
|
14
14
|
}
|
|
15
15
|
export function IframeChrome({ children, onClose, isFrameLoaded, }) {
|
|
16
|
-
const { setIframeAborted, iframeMode
|
|
16
|
+
const { setIframeAborted, iframeMode } = useIframe();
|
|
17
17
|
const iframeContainerStyleOverrides = iframeMode === "embedded"
|
|
18
18
|
? {
|
|
19
19
|
paddingTop: "1.5rem",
|
|
@@ -45,7 +45,6 @@ export function IframeChrome({ children, onClose, isFrameLoaded, }) {
|
|
|
45
45
|
}, children: _jsxs("div", { "data-testid": "iframe-chrome", style: {
|
|
46
46
|
position: "relative",
|
|
47
47
|
overflow: "hidden",
|
|
48
|
-
backgroundColor,
|
|
49
48
|
paddingLeft: "0",
|
|
50
49
|
paddingRight: "0",
|
|
51
50
|
paddingBottom: "0",
|
|
@@ -56,7 +55,7 @@ export function IframeChrome({ children, onClose, isFrameLoaded, }) {
|
|
|
56
55
|
}, onClick: (e) => e.stopPropagation(), children: [isFrameLoaded && (_jsx("button", { style: {
|
|
57
56
|
position: "absolute",
|
|
58
57
|
right: "1rem",
|
|
59
|
-
top: "
|
|
58
|
+
top: "2rem",
|
|
60
59
|
display: "flex",
|
|
61
60
|
cursor: "pointer",
|
|
62
61
|
alignItems: "center",
|
|
@@ -143,7 +142,13 @@ const CivicAuthIframeContainer = ({ onClose, closeOnRedirect = true, }) => {
|
|
|
143
142
|
}, [processIframeUrl, intervalId]);
|
|
144
143
|
const WrapperComponent = iframeMode === "embedded" ? NoChrome : IframeChrome;
|
|
145
144
|
const showLoadingIcon = !isIframeContentLoaded && iframeMode === "embedded";
|
|
146
|
-
|
|
145
|
+
const [isClient, setIsClient] = useState(false);
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
// only runs on client
|
|
148
|
+
setIsClient(true);
|
|
149
|
+
}, []);
|
|
150
|
+
// don't render the loading icon wrapper in server-mode as the appearance changes after load
|
|
151
|
+
return (_jsxs(WrapperComponent, { onClose: onClose, isFrameLoaded: isIframeContentLoaded, children: [showLoadingIcon && isClient ? (_jsx("div", { id: "civic-auth-loading-icon-wrapper", style: {
|
|
147
152
|
position: "absolute",
|
|
148
153
|
inset: 0,
|
|
149
154
|
display: "flex",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CivicAuthIframeContainer.js","sourceRoot":"","sources":["../../../src/shared/components/CivicAuthIframeContainer.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MA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B,EAAE,wBAAwB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1E,MAAM,gBAAgB,GAAG,WAAW,CAAC,GAAG,EAAE;QACxC,wBAAwB,CAAC,IAAI,CAAC,CAAC;QAE/B,MAAM,YAAY,GAAG,gBAAgB,EAAE,CAAC;QACxC,IAAI,YAAY,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;YACvC,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC;IACH,CAAC,EAAE,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC,CAAC;IAEnC,MAAM,gBAAgB,GAAG,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC;IAE7E,MAAM,eAAe,GAAG,CAAC,qBAAqB,IAAI,UAAU,KAAK,UAAU,CAAC;IAC5E,OAAO,CACL,MAAC,gBAAgB,IAAC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,qBAAqB,aACrE,eAAe,CAAC,CAAC,CAAC,CACjB,cACE,EAAE,EAAC,iCAAiC,EACpC,KAAK,EAAE;oBACL,QAAQ,EAAE,UAAU;oBACpB,KAAK,EAAE,CAAC;oBACR,OAAO,EAAE,MAAM;oBACf,UAAU,EAAE,QAAQ;oBACpB,cAAc,EAAE,QAAQ;oBACxB,eAAe;oBACf,YAAY,EAAE,MAAM;iBACrB,YAED,KAAC,WAAW,KAAG,GACX,CACP,CAAC,CAAC,CAAC,IAAI,EACR,KAAC,eAAe,IACd,GAAG,EAAE,SAAS,EACd,EAAE,EAAE,mBAAmB,EACvB,MAAM,EAAE,gBAAgB,GACxB,IACe,CACpB,CAAC;AACJ,CAAC,CAAC;AAIF,OAAO,EAAE,wBAAwB,EAAE,CAAC","sourcesContent":["\"use client\";\n\nimport React, { useCallback, useEffect, useRef, useState } from \"react\";\nimport { LoadingIcon } from \"@/shared/components/LoadingIcon.js\";\nimport { CloseIcon } from \"@/shared/components/CloseIcon.js\";\nimport { CivicAuthIframe } from \"@/shared/components/CivicAuthIframe.js\";\nimport { useIframe } from \"@/shared/hooks/index.js\";\nimport { TOKEN_EXCHANGE_TRIGGER_TEXT } from \"@/constants.js\";\nimport { useCivicAuthConfig } from \"@/shared/hooks/index.js\";\nimport { useClientTokenExchangeSession } from \"@/shared/hooks/index.js\";\nimport { getIframeRef } from \"../lib/iframeUtils.js\";\n\ntype CivicAuthIframeContainerProps = {\n onClose?: () => void;\n closeOnRedirect?: boolean;\n};\n\nfunction NoChrome({\n children,\n}: {\n children: React.ReactNode;\n onClose?: () => void;\n}) {\n return (\n <div data-testid=\"civic-iframe-no-chrome\" style={{ position: \"relative\" }}>\n {children}\n </div>\n );\n}\n\nexport function IframeChrome({\n children,\n onClose,\n isFrameLoaded,\n}: {\n children: React.ReactNode;\n onClose?: () => void;\n isFrameLoaded: boolean;\n}) {\n const { setIframeAborted, iframeMode, backgroundColor } = useIframe();\n\n const iframeContainerStyleOverrides =\n iframeMode === \"embedded\"\n ? {\n paddingTop: \"1.5rem\",\n borderRadius: \"1.5rem\",\n }\n : {\n ...(isFrameLoaded\n ? {\n paddingTop: \"1.5rem\",\n borderRadius: \"1.5rem\",\n }\n : { borderRadius: \"0.5rem\", paddingTop: \"0\" }),\n };\n return (\n <div\n style={{\n position: \"fixed\", // Change to fixed to stay in viewport\n left: 0,\n top: 0,\n zIndex: 50,\n display: \"flex\",\n height: \"100vh\",\n width: \"100vw\",\n alignItems: \"center\",\n justifyContent: \"center\",\n backgroundColor: \"rgba(17, 24, 39, 0.5)\", // Semi-transparent dark background\n backdropFilter: \"blur(4px)\", // Optional: adds slight blur to background\n }}\n onClick={() => {\n setIframeAborted(true);\n onClose?.();\n }}\n >\n <div\n data-testid=\"iframe-chrome\"\n style={{\n position: \"relative\",\n overflow: \"hidden\",\n backgroundColor,\n paddingLeft: \"0\",\n paddingRight: \"0\",\n paddingBottom: \"0\",\n // paddingTop gets added in style overrides\n ...iframeContainerStyleOverrides,\n boxShadow:\n \"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)\",\n minWidth: \"20rem\",\n }}\n onClick={(e) => e.stopPropagation()}\n >\n {isFrameLoaded && (\n <button\n style={{\n position: \"absolute\",\n right: \"1rem\",\n top: \"1rem\",\n display: \"flex\",\n cursor: \"pointer\",\n alignItems: \"center\",\n justifyContent: \"center\",\n border: \"none\",\n backgroundColor: \"transparent\",\n padding: \"0.25rem\",\n color: \"#9ca3af\",\n }}\n onClick={() => {\n setIframeAborted(true);\n onClose?.();\n }}\n >\n <CloseIcon />\n </button>\n )}\n\n {children}\n </div>\n </div>\n );\n}\n\nconst CivicAuthIframeContainer = ({\n onClose,\n closeOnRedirect = true,\n}: CivicAuthIframeContainerProps) => {\n const config = useCivicAuthConfig();\n const [tokenExchangeUrl, setTokenExchangeUrl] = useState<string | null>(null);\n const { doTokenExchange } = useClientTokenExchangeSession();\n const { iframeRef, iframeMode, backgroundColor, setIframeMounted } =\n useIframe();\n\n useEffect(() => {\n setIframeMounted(true);\n }, [setIframeMounted]);\n\n useEffect(() => {\n if (tokenExchangeUrl) {\n doTokenExchange?.(tokenExchangeUrl);\n }\n }, [doTokenExchange, tokenExchangeUrl]);\n\n const processIframeUrl = useCallback(() => {\n if (!config) return;\n if (iframeRef && iframeRef.current) {\n const ref = getIframeRef(iframeRef.current)!;\n if (ref.contentWindow) {\n try {\n const iframeUrl = ref.contentWindow.location.href;\n // we know that oauth has finished when the iframe redirects to our redirectUrl\n if (iframeUrl.startsWith(config.redirectUrl)) {\n const iframeBody = ref.contentWindow.document.body.innerHTML;\n\n // If we're doing a server token exchange, we need to call the server a second time\n // using a fetch so that we're on the same domain and cookies can be sent and read\n // The server will use the presence of the code_verifier cookie to determine whether to do a token exchange or not.\n // On the initial (3rd party) redirect from the auth server, the cookie won't be sent, so the server-side callback route will just render a blank page,\n // and we'll do the exchange request from here, which will include the cookies.\n if (iframeBody.includes(TOKEN_EXCHANGE_TRIGGER_TEXT)) {\n const params = new URL(iframeUrl).searchParams;\n const appUrl = globalThis.window?.location?.origin;\n fetch(\n `${config.redirectUrl}?${params.toString()}&appUrl=${appUrl}`,\n );\n } else {\n // if we're doing token-exchange in the client, we can just set the authResponseUrl\n // to be handled by the auth provider\n // iframeRef.current.setAttribute(\"src\", \"\");\n setTokenExchangeUrl(iframeUrl);\n }\n\n if (closeOnRedirect) onClose?.();\n return true; // Successfully processed the URL\n }\n } catch {\n // ignore errors while waiting for redirect\n }\n }\n }\n return false; // Haven't processed the URL yet\n }, [closeOnRedirect, config, iframeRef, onClose]);\n\n const intervalId = useRef<NodeJS.Timeout>();\n\n const handleEscape = useCallback(\n (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n onClose?.();\n }\n },\n [onClose],\n );\n\n // handle Escape\n useEffect(() => {\n window.addEventListener(\"keydown\", handleEscape);\n\n return () => window.removeEventListener(\"keydown\", handleEscape);\n });\n\n const [isIframeContentLoaded, setIsIframeContentLoaded] = useState(false);\n const handleIframeLoad = useCallback(() => {\n setIsIframeContentLoaded(true);\n\n const iframeHasUrl = processIframeUrl();\n if (iframeHasUrl && intervalId.current) {\n clearInterval(intervalId.current);\n }\n }, [processIframeUrl, intervalId]);\n\n const WrapperComponent = iframeMode === \"embedded\" ? NoChrome : IframeChrome;\n\n const showLoadingIcon = !isIframeContentLoaded && iframeMode === \"embedded\";\n return (\n <WrapperComponent onClose={onClose} isFrameLoaded={isIframeContentLoaded}>\n {showLoadingIcon ? (\n <div\n id=\"civic-auth-loading-icon-wrapper\"\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n backgroundColor,\n borderRadius: \"24px\",\n }}\n >\n <LoadingIcon />\n </div>\n ) : null}\n <CivicAuthIframe\n ref={iframeRef}\n id={\"civic-auth-iframe\"}\n onLoad={handleIframeLoad}\n />\n </WrapperComponent>\n );\n};\n\nexport type { CivicAuthIframeContainerProps };\n\nexport { CivicAuthIframeContainer };\n"]}
|
|
1
|
+
{"version":3,"file":"CivicAuthIframeContainer.js","sourceRoot":"","sources":["../../../src/shared/components/CivicAuthIframeContainer.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,6BAA6B,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAOrD,SAAS,QAAQ,CAAC,EAChB,QAAQ,GAIT;IACC,OAAO,CACL,6BAAiB,wBAAwB,EAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,YACtE,QAAQ,GACL,CACP,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,EAC3B,QAAQ,EACR,OAAO,EACP,aAAa,GAKd;IACC,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,GAAG,SAAS,EAAE,CAAC;IAErD,MAAM,6BAA6B,GACjC,UAAU,KAAK,UAAU;QACvB,CAAC,CAAC;YACE,UAAU,EAAE,QAAQ;YACpB,YAAY,EAAE,QAAQ;SACvB;QACH,CAAC,CAAC;YACE,GAAG,CAAC,aAAa;gBACf,CAAC,CAAC;oBACE,UAAU,EAAE,QAAQ;oBACpB,YAAY,EAAE,QAAQ;iBACvB;gBACH,CAAC,CAAC,EAAE,YAAY,EA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;oBACxB,eAAe;oBACf,YAAY,EAAE,MAAM;iBACrB,YAED,KAAC,WAAW,KAAG,GACX,CACP,CAAC,CAAC,CAAC,IAAI,EACR,KAAC,eAAe,IACd,GAAG,EAAE,SAAS,EACd,EAAE,EAAE,mBAAmB,EACvB,MAAM,EAAE,gBAAgB,GACxB,IACe,CACpB,CAAC;AACJ,CAAC,CAAC;AAIF,OAAO,EAAE,wBAAwB,EAAE,CAAC","sourcesContent":["\"use client\";\n\nimport React, { useCallback, useEffect, useRef, useState } from \"react\";\nimport { LoadingIcon } from \"@/shared/components/LoadingIcon.js\";\nimport { CloseIcon } from \"@/shared/components/CloseIcon.js\";\nimport { CivicAuthIframe } from \"@/shared/components/CivicAuthIframe.js\";\nimport { useIframe } from \"@/shared/hooks/index.js\";\nimport { TOKEN_EXCHANGE_TRIGGER_TEXT } from \"@/constants.js\";\nimport { useCivicAuthConfig } from \"@/shared/hooks/index.js\";\nimport { useClientTokenExchangeSession } from \"@/shared/hooks/index.js\";\nimport { getIframeRef } from \"../lib/iframeUtils.js\";\n\ntype CivicAuthIframeContainerProps = {\n onClose?: () => void;\n closeOnRedirect?: boolean;\n};\n\nfunction NoChrome({\n children,\n}: {\n children: React.ReactNode;\n onClose?: () => void;\n}) {\n return (\n <div data-testid=\"civic-iframe-no-chrome\" style={{ position: \"relative\" }}>\n {children}\n </div>\n );\n}\n\nexport function IframeChrome({\n children,\n onClose,\n isFrameLoaded,\n}: {\n children: React.ReactNode;\n onClose?: () => void;\n isFrameLoaded: boolean;\n}) {\n const { setIframeAborted, iframeMode } = useIframe();\n\n const iframeContainerStyleOverrides =\n iframeMode === \"embedded\"\n ? {\n paddingTop: \"1.5rem\",\n borderRadius: \"1.5rem\",\n }\n : {\n ...(isFrameLoaded\n ? {\n paddingTop: \"1.5rem\",\n borderRadius: \"1.5rem\",\n }\n : { borderRadius: \"0.5rem\", paddingTop: \"0\" }),\n };\n return (\n <div\n style={{\n position: \"fixed\", // Change to fixed to stay in viewport\n left: 0,\n top: 0,\n zIndex: 50,\n display: \"flex\",\n height: \"100vh\",\n width: \"100vw\",\n alignItems: \"center\",\n justifyContent: \"center\",\n backgroundColor: \"rgba(17, 24, 39, 0.5)\", // Semi-transparent dark background\n backdropFilter: \"blur(4px)\", // Optional: adds slight blur to background\n }}\n onClick={() => {\n setIframeAborted(true);\n onClose?.();\n }}\n >\n <div\n data-testid=\"iframe-chrome\"\n style={{\n position: \"relative\",\n overflow: \"hidden\",\n paddingLeft: \"0\",\n paddingRight: \"0\",\n paddingBottom: \"0\",\n // paddingTop gets added in style overrides\n ...iframeContainerStyleOverrides,\n boxShadow:\n \"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)\",\n minWidth: \"20rem\",\n }}\n onClick={(e) => e.stopPropagation()}\n >\n {isFrameLoaded && (\n <button\n style={{\n position: \"absolute\",\n right: \"1rem\",\n top: \"2rem\",\n display: \"flex\",\n cursor: \"pointer\",\n alignItems: \"center\",\n justifyContent: \"center\",\n border: \"none\",\n backgroundColor: \"transparent\",\n padding: \"0.25rem\",\n color: \"#9ca3af\",\n }}\n onClick={() => {\n setIframeAborted(true);\n onClose?.();\n }}\n >\n <CloseIcon />\n </button>\n )}\n\n {children}\n </div>\n </div>\n );\n}\n\nconst CivicAuthIframeContainer = ({\n onClose,\n closeOnRedirect = true,\n}: CivicAuthIframeContainerProps) => {\n const config = useCivicAuthConfig();\n const [tokenExchangeUrl, setTokenExchangeUrl] = useState<string | null>(null);\n const { doTokenExchange } = useClientTokenExchangeSession();\n const { iframeRef, iframeMode, backgroundColor, setIframeMounted } =\n useIframe();\n\n useEffect(() => {\n setIframeMounted(true);\n }, [setIframeMounted]);\n\n useEffect(() => {\n if (tokenExchangeUrl) {\n doTokenExchange?.(tokenExchangeUrl);\n }\n }, [doTokenExchange, tokenExchangeUrl]);\n\n const processIframeUrl = useCallback(() => {\n if (!config) return;\n if (iframeRef && iframeRef.current) {\n const ref = getIframeRef(iframeRef.current)!;\n if (ref.contentWindow) {\n try {\n const iframeUrl = ref.contentWindow.location.href;\n // we know that oauth has finished when the iframe redirects to our redirectUrl\n if (iframeUrl.startsWith(config.redirectUrl)) {\n const iframeBody = ref.contentWindow.document.body.innerHTML;\n\n // If we're doing a server token exchange, we need to call the server a second time\n // using a fetch so that we're on the same domain and cookies can be sent and read\n // The server will use the presence of the code_verifier cookie to determine whether to do a token exchange or not.\n // On the initial (3rd party) redirect from the auth server, the cookie won't be sent, so the server-side callback route will just render a blank page,\n // and we'll do the exchange request from here, which will include the cookies.\n if (iframeBody.includes(TOKEN_EXCHANGE_TRIGGER_TEXT)) {\n const params = new URL(iframeUrl).searchParams;\n const appUrl = globalThis.window?.location?.origin;\n fetch(\n `${config.redirectUrl}?${params.toString()}&appUrl=${appUrl}`,\n );\n } else {\n // if we're doing token-exchange in the client, we can just set the authResponseUrl\n // to be handled by the auth provider\n // iframeRef.current.setAttribute(\"src\", \"\");\n setTokenExchangeUrl(iframeUrl);\n }\n\n if (closeOnRedirect) onClose?.();\n return true; // Successfully processed the URL\n }\n } catch {\n // ignore errors while waiting for redirect\n }\n }\n }\n return false; // Haven't processed the URL yet\n }, [closeOnRedirect, config, iframeRef, onClose]);\n\n const intervalId = useRef<NodeJS.Timeout>();\n\n const handleEscape = useCallback(\n (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n onClose?.();\n }\n },\n [onClose],\n );\n\n // handle Escape\n useEffect(() => {\n window.addEventListener(\"keydown\", handleEscape);\n\n return () => window.removeEventListener(\"keydown\", handleEscape);\n });\n\n const [isIframeContentLoaded, setIsIframeContentLoaded] = useState(false);\n const handleIframeLoad = useCallback(() => {\n setIsIframeContentLoaded(true);\n\n const iframeHasUrl = processIframeUrl();\n if (iframeHasUrl && intervalId.current) {\n clearInterval(intervalId.current);\n }\n }, [processIframeUrl, intervalId]);\n\n const WrapperComponent = iframeMode === \"embedded\" ? NoChrome : IframeChrome;\n\n const showLoadingIcon = !isIframeContentLoaded && iframeMode === \"embedded\";\n const [isClient, setIsClient] = useState(false);\n useEffect(() => {\n // only runs on client\n setIsClient(true);\n }, []);\n // don't render the loading icon wrapper in server-mode as the appearance changes after load\n return (\n <WrapperComponent onClose={onClose} isFrameLoaded={isIframeContentLoaded}>\n {showLoadingIcon && isClient ? (\n <div\n id=\"civic-auth-loading-icon-wrapper\"\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n backgroundColor,\n borderRadius: \"24px\",\n }}\n >\n <LoadingIcon />\n </div>\n ) : null}\n <CivicAuthIframe\n ref={iframeRef}\n id={\"civic-auth-iframe\"}\n onLoad={handleIframeLoad}\n />\n </WrapperComponent>\n );\n};\n\nexport type { CivicAuthIframeContainerProps };\n\nexport { CivicAuthIframeContainer };\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type CivicAuthLogoutIframeContainerProps = {
|
|
2
2
|
isLoading?: boolean;
|
|
3
3
|
};
|
|
4
|
-
declare const CivicAuthLogoutIframeContainer: ({ isLoading, }: CivicAuthLogoutIframeContainerProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
4
|
+
declare const CivicAuthLogoutIframeContainer: ({ isLoading, }: CivicAuthLogoutIframeContainerProps) => import("@emotion/react/jsx-runtime").JSX.Element | null;
|
|
5
5
|
export { CivicAuthLogoutIframeContainer };
|
|
6
6
|
//# sourceMappingURL=CivicAuthLogoutIframeContainer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CivicAuthLogoutIframeContainer.d.ts","sourceRoot":"","sources":["../../../src/shared/components/CivicAuthLogoutIframeContainer.tsx"],"names":[],"mappings":"AAQA,KAAK,mCAAmC,GAAG;IACzC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,QAAA,MAAM,8BAA8B,GAAI,gBAErC,mCAAmC,
|
|
1
|
+
{"version":3,"file":"CivicAuthLogoutIframeContainer.d.ts","sourceRoot":"","sources":["../../../src/shared/components/CivicAuthLogoutIframeContainer.tsx"],"names":[],"mappings":"AAQA,KAAK,mCAAmC,GAAG;IACzC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,QAAA,MAAM,8BAA8B,GAAI,gBAErC,mCAAmC,4DA+BrC,CAAC;AAEF,OAAO,EAAE,8BAA8B,EAAE,CAAC"}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
3
|
-
import React from "react";
|
|
3
|
+
import React, { useEffect, useState } from "react";
|
|
4
4
|
import { CivicAuthIframe } from "../../shared/components/CivicAuthIframe.js";
|
|
5
5
|
import { useIframe } from "../../shared/hooks/index.js";
|
|
6
6
|
import { LoadingIcon } from "./LoadingIcon.js";
|
|
7
7
|
import { IframeChrome } from "./CivicAuthIframeContainer.js";
|
|
8
8
|
const CivicAuthLogoutIframeContainer = ({ isLoading = false, }) => {
|
|
9
9
|
const { logoutIframeRef } = useIframe();
|
|
10
|
-
|
|
10
|
+
const [isClient, setIsClient] = useState(false);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
// only runs on client
|
|
13
|
+
setIsClient(true);
|
|
14
|
+
}, []);
|
|
15
|
+
// don't render the in server-mode as the appearance changes after load
|
|
16
|
+
return !isClient ? null : (_jsxs(IframeChrome, { isFrameLoaded: true, children: [isLoading ? (_jsx("div", { id: "civic-auth-loading-icon-wrapper", style: {
|
|
11
17
|
position: "absolute",
|
|
12
18
|
inset: 0,
|
|
13
19
|
display: "flex",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CivicAuthLogoutIframeContainer.js","sourceRoot":"","sources":["../../../src/shared/components/CivicAuthLogoutIframeContainer.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"CivicAuthLogoutIframeContainer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AC;AAEF,OAAO,EAAE,8BAA8B,EAAE,CAAC","sourcesContent":["\"use client\";\n\nimport React, { useEffect, useState } from \"react\";\nimport { CivicAuthIframe } from \"@/shared/components/CivicAuthIframe.js\";\nimport { useIframe } from \"@/shared/hooks/index.js\";\nimport { LoadingIcon } from \"./LoadingIcon.js\";\nimport { IframeChrome } from \"./CivicAuthIframeContainer.js\";\n\ntype CivicAuthLogoutIframeContainerProps = {\n isLoading?: boolean;\n};\n\nconst CivicAuthLogoutIframeContainer = ({\n isLoading = false,\n}: CivicAuthLogoutIframeContainerProps) => {\n const { logoutIframeRef } = useIframe();\n const [isClient, setIsClient] = useState(false);\n useEffect(() => {\n // only runs on client\n setIsClient(true);\n }, []);\n // don't render the in server-mode as the appearance changes after load\n return !isClient ? null : (\n <IframeChrome isFrameLoaded={true}>\n {isLoading ? (\n <div\n id=\"civic-auth-loading-icon-wrapper\"\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n }}\n >\n <LoadingIcon />\n </div>\n ) : null}\n <CivicAuthIframe\n ref={logoutIframeRef}\n id={\"civic-auth-logout-iframe\"}\n onLoad={() => {}}\n />\n </IframeChrome>\n );\n};\n\nexport { CivicAuthLogoutIframeContainer };\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type ExtendedIframeElement = HTMLIFrameElement & {
|
|
2
|
-
|
|
2
|
+
getIframeElement: () => HTMLIFrameElement;
|
|
3
3
|
};
|
|
4
4
|
export declare const getIframeRef: (iframeRef: HTMLIFrameElement | ExtendedIframeElement | null | undefined, allowNull?: boolean) => HTMLIFrameElement;
|
|
5
5
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframeUtils.d.ts","sourceRoot":"","sources":["../../../src/shared/lib/iframeUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"iframeUtils.d.ts","sourceRoot":"","sources":["../../../src/shared/lib/iframeUtils.ts"],"names":[],"mappings":"AAEA,KAAK,qBAAqB,GAAG,iBAAiB,GAAG;IAE/C,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;CAC3C,CAAC;AACF,eAAO,MAAM,YAAY,GACvB,WAAW,iBAAiB,GAAG,qBAAqB,GAAG,IAAI,GAAG,SAAS,EACvE,mBAAiB,KAChB,iBAOF,CAAC"}
|
|
@@ -2,6 +2,6 @@ export const getIframeRef = (iframeRef, allowNull = false) => {
|
|
|
2
2
|
if (!iframeRef && !allowNull) {
|
|
3
3
|
throw new Error("iframeRef is required for displayMode 'iframe'");
|
|
4
4
|
}
|
|
5
|
-
return iframeRef?.
|
|
5
|
+
return (iframeRef?.getIframeElement?.() ?? iframeRef);
|
|
6
6
|
};
|
|
7
7
|
//# sourceMappingURL=iframeUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframeUtils.js","sourceRoot":"","sources":["../../../src/shared/lib/iframeUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"iframeUtils.js","sourceRoot":"","sources":["../../../src/shared/lib/iframeUtils.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,SAAuE,EACvE,SAAS,GAAG,KAAK,EACE,EAAE;IACrB,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,CACJ,SAAmC,EAAE,gBAAgB,EAAE,EAAE,IAAI,SAAS,CACxE,CAAC;AACJ,CAAC,CAAC","sourcesContent":["// the latest version of iframe resizer uses 'getElement' but the old version uses 'getIframeElement'\n// the latest version is currently broken so we're temporarily using the old version\ntype ExtendedIframeElement = HTMLIFrameElement & {\n // getElement: () => HTMLIFrameElement;\n getIframeElement: () => HTMLIFrameElement;\n};\nexport const getIframeRef = (\n iframeRef: HTMLIFrameElement | ExtendedIframeElement | null | undefined,\n allowNull = false,\n): HTMLIFrameElement => {\n if (!iframeRef && !allowNull) {\n throw new Error(\"iframeRef is required for displayMode 'iframe'\");\n }\n return (\n (iframeRef as ExtendedIframeElement)?.getIframeElement?.() ?? iframeRef\n );\n};\n"]}
|
package/dist/shared/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "@civic/auth:0.4.1";
|
|
1
|
+
export declare const VERSION = "@civic/auth:0.4.2-beta.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,6BAA6B,CAAC"}
|
package/dist/shared/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAE/C,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAE/C,MAAM,CAAC,MAAM,OAAO,GAAG,0BAA0B,CAAC","sourcesContent":["// This is an auto-generated file. Do not edit.\n\nexport const VERSION = \"@civic/auth:0.4.2-beta.1\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@civic/auth",
|
|
3
|
-
"version": "0.4.1",
|
|
3
|
+
"version": "0.4.2-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@emotion/react": "^11.14.0",
|
|
42
|
-
"
|
|
42
|
+
"iframe-resizer-react": "1.1.1",
|
|
43
43
|
"debug": "^4.3.7",
|
|
44
44
|
"eventemitter3": "^5.0.1",
|
|
45
45
|
"jose": "^5.9.4",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"esbuild-plugin-css-modules": "^0.3.0",
|
|
65
65
|
"eslint": "^8.57.1",
|
|
66
66
|
"eslint-plugin-require-extensions": "^0.1.3",
|
|
67
|
-
"next": "14.2.15",
|
|
67
|
+
"next": "^14.2.15",
|
|
68
68
|
"prettier": "^3.3.3",
|
|
69
69
|
"react": "18.3.1",
|
|
70
70
|
"react-dom": "18.3.1",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"@repo/typescript-config": "0.0.0"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"next": ">=
|
|
82
|
+
"next": "^14.2.25 || >=15.2.3",
|
|
83
83
|
"react": ">=18"
|
|
84
84
|
},
|
|
85
85
|
"peerDependenciesMeta": {
|