@smg-automotive/auth 6.8.0-auth0-update-root.9 → 6.8.0-auth0-update-switch-tenant.2

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 (64) hide show
  1. package/dist/cjs/client/helpers/getAccessToken.d.ts +4 -0
  2. package/dist/cjs/client/helpers/getAccessToken.js +27 -0
  3. package/dist/cjs/client/helpers/getAccessToken.js.map +1 -0
  4. package/dist/cjs/client/helpers/index.d.ts +2 -0
  5. package/dist/cjs/client/helpers/switchSelectedTenant.d.ts +5 -0
  6. package/dist/cjs/client/helpers/switchSelectedTenant.js +25 -0
  7. package/dist/cjs/client/helpers/switchSelectedTenant.js.map +1 -0
  8. package/dist/cjs/client/hooks/__tests__/UseUser.Test.d.ts +1 -0
  9. package/dist/cjs/client/hooks/index.d.ts +1 -0
  10. package/dist/cjs/client/hooks/useUser.d.ts +9 -0
  11. package/dist/cjs/client/hooks/useUser.js +26 -0
  12. package/dist/cjs/client/hooks/useUser.js.map +1 -0
  13. package/dist/cjs/index.d.ts +2 -0
  14. package/dist/cjs/index.js +9 -1
  15. package/dist/cjs/index.js.map +1 -1
  16. package/dist/cjs/server/getAuth0Instance.d.ts +1 -2
  17. package/dist/cjs/server/helpers/getAccessToken.d.ts +2 -0
  18. package/dist/cjs/server/helpers/getAccessToken.js +12 -0
  19. package/dist/cjs/server/helpers/getAccessToken.js.map +1 -0
  20. package/dist/cjs/server/helpers/getUser.d.ts +3 -0
  21. package/dist/cjs/server/helpers/getUser.js +14 -0
  22. package/dist/cjs/server/helpers/getUser.js.map +1 -0
  23. package/dist/cjs/server/helpers/index.d.ts +3 -0
  24. package/dist/cjs/server/helpers/isLoggedIn.d.ts +2 -0
  25. package/dist/cjs/server/helpers/isLoggedIn.js +11 -0
  26. package/dist/cjs/server/helpers/isLoggedIn.js.map +1 -0
  27. package/dist/cjs/server.d.ts +2 -1
  28. package/dist/cjs/server.js +6 -0
  29. package/dist/cjs/server.js.map +1 -1
  30. package/dist/config-U4mojGmR.d.ts +38 -0
  31. package/dist/esm/client/helpers/getAccessToken.d.ts +4 -0
  32. package/dist/esm/client/helpers/getAccessToken.js +25 -0
  33. package/dist/esm/client/helpers/getAccessToken.js.map +1 -0
  34. package/dist/esm/client/helpers/index.d.ts +2 -0
  35. package/dist/esm/client/helpers/switchSelectedTenant.d.ts +5 -0
  36. package/dist/esm/client/helpers/switchSelectedTenant.js +23 -0
  37. package/dist/esm/client/helpers/switchSelectedTenant.js.map +1 -0
  38. package/dist/esm/client/hooks/__tests__/UseUser.Test.d.ts +1 -0
  39. package/dist/esm/client/hooks/index.d.ts +1 -0
  40. package/dist/esm/client/hooks/useUser.d.ts +9 -0
  41. package/dist/esm/client/hooks/useUser.js +24 -0
  42. package/dist/esm/client/hooks/useUser.js.map +1 -0
  43. package/dist/esm/index.d.ts +2 -0
  44. package/dist/esm/index.js +3 -1
  45. package/dist/esm/index.js.map +1 -1
  46. package/dist/esm/server/getAuth0Instance.d.ts +1 -2
  47. package/dist/esm/server/helpers/getAccessToken.d.ts +2 -0
  48. package/dist/esm/server/helpers/getAccessToken.js +10 -0
  49. package/dist/esm/server/helpers/getAccessToken.js.map +1 -0
  50. package/dist/esm/server/helpers/getUser.d.ts +3 -0
  51. package/dist/esm/server/helpers/getUser.js +12 -0
  52. package/dist/esm/server/helpers/getUser.js.map +1 -0
  53. package/dist/esm/server/helpers/index.d.ts +3 -0
  54. package/dist/esm/server/helpers/isLoggedIn.d.ts +2 -0
  55. package/dist/esm/server/helpers/isLoggedIn.js +9 -0
  56. package/dist/esm/server/helpers/isLoggedIn.js.map +1 -0
  57. package/dist/esm/server.d.ts +2 -1
  58. package/dist/esm/server.js +3 -0
  59. package/dist/esm/server.js.map +1 -1
  60. package/dist/fixtures.d.ts +3 -80
  61. package/dist/index.d.ts +22 -1
  62. package/dist/server.d.ts +14 -1
  63. package/dist/sessionUser-cqv4vnLO.d.ts +45 -0
  64. package/package.json +7 -4
@@ -0,0 +1,4 @@
1
+ import { Auth0Config } from 'src/types';
2
+ export declare const getAccessToken: ({ config }: {
3
+ config: Auth0Config;
4
+ }) => Promise<any>;
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ var errors = require('@auth0/nextjs-auth0/errors');
4
+
5
+ const getAccessToken = async ({ config }) => {
6
+ const tokenResponse = await fetch(config.tokenEndpoint, {
7
+ method: 'GET',
8
+ headers: {
9
+ 'Content-Type': 'application/json',
10
+ },
11
+ });
12
+ if (!tokenResponse.ok) {
13
+ let accessTokenError;
14
+ try {
15
+ accessTokenError = await tokenResponse.json();
16
+ }
17
+ catch {
18
+ throw new Error('Unexpected error when getting access token');
19
+ }
20
+ throw new errors.AccessTokenError(accessTokenError.error.code, accessTokenError.error.message);
21
+ }
22
+ const tokenSet = await tokenResponse.json();
23
+ return tokenSet.token;
24
+ };
25
+
26
+ exports.getAccessToken = getAccessToken;
27
+ //# sourceMappingURL=getAccessToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getAccessToken.js","sources":["../../../../../src/client/helpers/getAccessToken.ts"],"sourcesContent":[null],"names":["AccessTokenError"],"mappings":";;;;AAIO,MAAM,cAAc,GAAG,OAAO,EAAE,MAAM,EAA2B,KAAI;IAC1E,MAAM,aAAa,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,aAAa,EAAE;AACtD,QAAA,MAAM,EAAE,KAAK;AACb,QAAA,OAAO,EAAE;AACP,YAAA,cAAc,EAAE,kBAAkB;AACnC,SAAA;AACF,KAAA,CAAC;AAEF,IAAA,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE;AACrB,QAAA,IAAI,gBAAgB;AAEpB,QAAA,IAAI;AACF,YAAA,gBAAgB,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE;QAC/C;AAAE,QAAA,MAAM;AACN,YAAA,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC;QAC/D;AAEA,QAAA,MAAM,IAAIA,uBAAgB,CACxB,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAC3B,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAC/B;IACH;AAEA,IAAA,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE;IAC3C,OAAO,QAAQ,CAAC,KAAK;AACvB;;;;"}
@@ -0,0 +1,2 @@
1
+ export { getAccessToken } from './getAccessToken';
2
+ export { switchSelectedTenant } from './switchSelectedTenant';
@@ -0,0 +1,5 @@
1
+ import { Auth0Config } from 'src/types';
2
+ export declare const switchSelectedTenant: ({ config, sellerId, }: {
3
+ config: Auth0Config;
4
+ sellerId: string;
5
+ }) => Promise<void>;
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var errors = require('@auth0/nextjs-auth0/errors');
4
+
5
+ const switchSelectedTenant = async ({ config, sellerId, }) => {
6
+ const tokenResponse = await fetch(`${config.tokenEndpoint}?sellerId=${sellerId}`, {
7
+ method: 'GET',
8
+ headers: {
9
+ 'Content-Type': 'application/json',
10
+ },
11
+ });
12
+ if (!tokenResponse.ok) {
13
+ let accessTokenError;
14
+ try {
15
+ accessTokenError = await tokenResponse.json();
16
+ }
17
+ catch {
18
+ throw new Error('Unexpected error when switching selected tenant');
19
+ }
20
+ throw new errors.AccessTokenError(accessTokenError.error.code, accessTokenError.error.message);
21
+ }
22
+ };
23
+
24
+ exports.switchSelectedTenant = switchSelectedTenant;
25
+ //# sourceMappingURL=switchSelectedTenant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switchSelectedTenant.js","sources":["../../../../../src/client/helpers/switchSelectedTenant.ts"],"sourcesContent":[null],"names":["AccessTokenError"],"mappings":";;;;AAIO,MAAM,oBAAoB,GAAG,OAAO,EACzC,MAAM,EACN,QAAQ,GAIT,KAAmB;AAClB,IAAA,MAAM,aAAa,GAAG,MAAM,KAAK,CAC/B,CAAA,EAAG,MAAM,CAAC,aAAa,CAAA,UAAA,EAAa,QAAQ,CAAA,CAAE,EAC9C;AACE,QAAA,MAAM,EAAE,KAAK;AACb,QAAA,OAAO,EAAE;AACP,YAAA,cAAc,EAAE,kBAAkB;AACnC,SAAA;AACF,KAAA,CACF;AAED,IAAA,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE;AACrB,QAAA,IAAI,gBAAgB;AAEpB,QAAA,IAAI;AACF,YAAA,gBAAgB,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE;QAC/C;AAAE,QAAA,MAAM;AACN,YAAA,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC;QACpE;AAEA,QAAA,MAAM,IAAIA,uBAAgB,CACxB,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAC3B,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAC/B;IACH;AACF;;;;"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { useUser } from './useUser';
@@ -0,0 +1,9 @@
1
+ import { Auth0Config, EnrichedSessionUser } from 'src/types';
2
+ export declare const useUser: ({ config }: {
3
+ config: Auth0Config;
4
+ }) => {
5
+ user: EnrichedSessionUser | null;
6
+ error: Error | null;
7
+ isLoading: boolean;
8
+ invalidate: () => Promise<EnrichedSessionUser | undefined>;
9
+ };
@@ -0,0 +1,26 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ var useSWR = require('swr');
5
+ var react = require('react');
6
+
7
+ const userFetcher = async (url) => {
8
+ const response = await fetch(url);
9
+ if (!response.ok) {
10
+ throw new Error('Unauthorized');
11
+ }
12
+ return response.json();
13
+ };
14
+ const useUser = ({ config }) => {
15
+ const { data, error, isLoading, mutate } = useSWR(config.userProfileEndpoint, userFetcher);
16
+ const invalidate = react.useCallback(() => mutate(), [mutate]);
17
+ return {
18
+ user: data ?? null,
19
+ error: error ?? null,
20
+ isLoading,
21
+ invalidate,
22
+ };
23
+ };
24
+
25
+ exports.useUser = useUser;
26
+ //# sourceMappingURL=useUser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUser.js","sources":["../../../../../src/client/hooks/useUser.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAOA;AACE;AACA;AACE;;AAGF;AACF;;AAGE;AAMA;;;;;;;AAQF;;"}
@@ -0,0 +1,2 @@
1
+ export * from './client/helpers';
2
+ export * from './client/hooks';
package/dist/cjs/index.js CHANGED
@@ -1,4 +1,12 @@
1
- "use strict";
2
1
  'use strict';
3
2
 
3
+ var getAccessToken = require('./client/helpers/getAccessToken.js');
4
+ var switchSelectedTenant = require('./client/helpers/switchSelectedTenant.js');
5
+ var useUser = require('./client/hooks/useUser.js');
6
+
7
+
8
+
9
+ exports.getAccessToken = getAccessToken.getAccessToken;
10
+ exports.switchSelectedTenant = switchSelectedTenant.switchSelectedTenant;
11
+ exports.useUser = useUser.useUser;
4
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { Auth0Client } from '@auth0/nextjs-auth0/server';
2
- type GetAuth0InstanceContext = {
2
+ export type GetAuth0InstanceContext = {
3
3
  protocol: string;
4
4
  host: string;
5
5
  isProxied: boolean;
@@ -7,4 +7,3 @@ type GetAuth0InstanceContext = {
7
7
  export declare const getAuth0Instance: ({ protocol, host, isProxied, onError, }: GetAuth0InstanceContext & {
8
8
  onError?: (error: Error) => void;
9
9
  }) => Auth0Client;
10
- export {};
@@ -0,0 +1,2 @@
1
+ import { GetAuth0InstanceContext } from '../getAuth0Instance';
2
+ export declare const getAccessToken: (context: GetAuth0InstanceContext) => Promise<string>;
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ var getAuth0Instance = require('../getAuth0Instance.js');
4
+
5
+ const getAccessToken = async (context) => {
6
+ const auth0Instance = getAuth0Instance.getAuth0Instance(context);
7
+ const { token } = await auth0Instance.getAccessToken();
8
+ return token;
9
+ };
10
+
11
+ exports.getAccessToken = getAccessToken;
12
+ //# sourceMappingURL=getAccessToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getAccessToken.js","sources":["../../../../../src/server/helpers/getAccessToken.ts"],"sourcesContent":[null],"names":["getAuth0Instance"],"mappings":";;;;MAEa,cAAc,GAAG,OAAO,OAAgC,KAAI;AACvE,IAAA,MAAM,aAAa,GAAGA,iCAAgB,CAAC,OAAO,CAAC;IAC/C,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,aAAa,CAAC,cAAc,EAAE;AACtD,IAAA,OAAO,KAAK;AACd;;;;"}
@@ -0,0 +1,3 @@
1
+ import { SessionUser } from 'src/types';
2
+ import { GetAuth0InstanceContext } from '../getAuth0Instance';
3
+ export declare const getUser: (context: GetAuth0InstanceContext) => Promise<SessionUser | null>;
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var getAuth0Instance = require('../getAuth0Instance.js');
4
+
5
+ const getUser = async (context) => {
6
+ const auth0Instance = getAuth0Instance.getAuth0Instance(context);
7
+ const sessionData = await auth0Instance.getSession();
8
+ if (!sessionData || !sessionData.user)
9
+ return null;
10
+ return sessionData.user;
11
+ };
12
+
13
+ exports.getUser = getUser;
14
+ //# sourceMappingURL=getUser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUser.js","sources":["../../../../../src/server/helpers/getUser.ts"],"sourcesContent":[null],"names":["getAuth0Instance"],"mappings":";;;;MAIa,OAAO,GAAG,OACrB,OAAgC,KACD;AAC/B,IAAA,MAAM,aAAa,GAAGA,iCAAgB,CAAC,OAAO,CAAC;AAC/C,IAAA,MAAM,WAAW,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE;AAEpD,IAAA,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,IAAI;AAAE,QAAA,OAAO,IAAI;IAElD,OAAO,WAAW,CAAC,IAAmB;AACxC;;;;"}
@@ -0,0 +1,3 @@
1
+ export { getAccessToken } from './getAccessToken';
2
+ export { getUser } from './getUser';
3
+ export { isLoggedIn } from './isLoggedIn';
@@ -0,0 +1,2 @@
1
+ import { GetAuth0InstanceContext } from '../getAuth0Instance';
2
+ export declare const isLoggedIn: (context: GetAuth0InstanceContext) => Promise<boolean>;
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var getUser = require('./getUser.js');
4
+
5
+ const isLoggedIn = async (context) => {
6
+ const user = await getUser.getUser(context);
7
+ return !!user;
8
+ };
9
+
10
+ exports.isLoggedIn = isLoggedIn;
11
+ //# sourceMappingURL=isLoggedIn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isLoggedIn.js","sources":["../../../../../src/server/helpers/isLoggedIn.ts"],"sourcesContent":[null],"names":["getUser"],"mappings":";;;;MAGa,UAAU,GAAG,OAAO,OAAgC,KAAI;AACnE,IAAA,MAAM,IAAI,GAAG,MAAMA,eAAO,CAAC,OAAO,CAAC;IACnC,OAAO,CAAC,CAAC,IAAI;AACf;;;;"}
@@ -1 +1,2 @@
1
- export { authMiddleware } from './server/middleware';
1
+ export * from './server/middleware';
2
+ export * from './server/helpers';
@@ -1,8 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('./server/middleware/index.js');
4
+ var getAccessToken = require('./server/helpers/getAccessToken.js');
5
+ var getUser = require('./server/helpers/getUser.js');
6
+ var isLoggedIn = require('./server/helpers/isLoggedIn.js');
4
7
 
5
8
 
6
9
 
7
10
  exports.authMiddleware = index.authMiddleware;
11
+ exports.getAccessToken = getAccessToken.getAccessToken;
12
+ exports.getUser = getUser.getUser;
13
+ exports.isLoggedIn = isLoggedIn.isLoggedIn;
8
14
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
1
+ {"version":3,"file":"server.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
@@ -0,0 +1,38 @@
1
+ import { Language } from '@smg-automotive/i18n-pkg';
2
+
3
+ type CookieOptions = {
4
+ name: string;
5
+ httpOnly: boolean;
6
+ maxAge: number;
7
+ secure: boolean;
8
+ sameSite: boolean | 'lax' | 'strict' | 'none' | undefined;
9
+ path: string;
10
+ };
11
+
12
+ type Auth0Config = {
13
+ loginEndpoint: string;
14
+ logoutEndpoint: string;
15
+ tokenEndpoint: string;
16
+ callbackEndpoint: string;
17
+ userProfileEndpoint: string;
18
+ intervalDelayInMs: number;
19
+ refreshThresholdInMs: number;
20
+ selectedSellerIdCookie: CookieOptions;
21
+ impersonatedSellerIdCookie: CookieOptions;
22
+ proxyPathSegment: string;
23
+ legacyAccessTokenName: string;
24
+ legacyRefreshTokenName: string;
25
+ providerInterval: number;
26
+ debugForceTokenRefresh: boolean;
27
+ languageConfig: {
28
+ default: Language;
29
+ supported: Language[];
30
+ };
31
+ scopes: string;
32
+ globalAuthErrorPath: string;
33
+ authCookieNames: string[];
34
+ sessionCookieName: string;
35
+ audience: string;
36
+ };
37
+
38
+ export type { Auth0Config as A };
@@ -0,0 +1,4 @@
1
+ import { Auth0Config } from 'src/types';
2
+ export declare const getAccessToken: ({ config }: {
3
+ config: Auth0Config;
4
+ }) => Promise<any>;
@@ -0,0 +1,25 @@
1
+ import { AccessTokenError } from '@auth0/nextjs-auth0/errors';
2
+
3
+ const getAccessToken = async ({ config }) => {
4
+ const tokenResponse = await fetch(config.tokenEndpoint, {
5
+ method: 'GET',
6
+ headers: {
7
+ 'Content-Type': 'application/json',
8
+ },
9
+ });
10
+ if (!tokenResponse.ok) {
11
+ let accessTokenError;
12
+ try {
13
+ accessTokenError = await tokenResponse.json();
14
+ }
15
+ catch {
16
+ throw new Error('Unexpected error when getting access token');
17
+ }
18
+ throw new AccessTokenError(accessTokenError.error.code, accessTokenError.error.message);
19
+ }
20
+ const tokenSet = await tokenResponse.json();
21
+ return tokenSet.token;
22
+ };
23
+
24
+ export { getAccessToken };
25
+ //# sourceMappingURL=getAccessToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getAccessToken.js","sources":["../../../../../src/client/helpers/getAccessToken.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAIO,MAAM,cAAc,GAAG,OAAO,EAAE,MAAM,EAA2B,KAAI;IAC1E,MAAM,aAAa,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,aAAa,EAAE;AACtD,QAAA,MAAM,EAAE,KAAK;AACb,QAAA,OAAO,EAAE;AACP,YAAA,cAAc,EAAE,kBAAkB;AACnC,SAAA;AACF,KAAA,CAAC;AAEF,IAAA,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE;AACrB,QAAA,IAAI,gBAAgB;AAEpB,QAAA,IAAI;AACF,YAAA,gBAAgB,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE;QAC/C;AAAE,QAAA,MAAM;AACN,YAAA,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC;QAC/D;AAEA,QAAA,MAAM,IAAI,gBAAgB,CACxB,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAC3B,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAC/B;IACH;AAEA,IAAA,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE;IAC3C,OAAO,QAAQ,CAAC,KAAK;AACvB;;;;"}
@@ -0,0 +1,2 @@
1
+ export { getAccessToken } from './getAccessToken';
2
+ export { switchSelectedTenant } from './switchSelectedTenant';
@@ -0,0 +1,5 @@
1
+ import { Auth0Config } from 'src/types';
2
+ export declare const switchSelectedTenant: ({ config, sellerId, }: {
3
+ config: Auth0Config;
4
+ sellerId: string;
5
+ }) => Promise<void>;
@@ -0,0 +1,23 @@
1
+ import { AccessTokenError } from '@auth0/nextjs-auth0/errors';
2
+
3
+ const switchSelectedTenant = async ({ config, sellerId, }) => {
4
+ const tokenResponse = await fetch(`${config.tokenEndpoint}?sellerId=${sellerId}`, {
5
+ method: 'GET',
6
+ headers: {
7
+ 'Content-Type': 'application/json',
8
+ },
9
+ });
10
+ if (!tokenResponse.ok) {
11
+ let accessTokenError;
12
+ try {
13
+ accessTokenError = await tokenResponse.json();
14
+ }
15
+ catch {
16
+ throw new Error('Unexpected error when switching selected tenant');
17
+ }
18
+ throw new AccessTokenError(accessTokenError.error.code, accessTokenError.error.message);
19
+ }
20
+ };
21
+
22
+ export { switchSelectedTenant };
23
+ //# sourceMappingURL=switchSelectedTenant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switchSelectedTenant.js","sources":["../../../../../src/client/helpers/switchSelectedTenant.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAIO,MAAM,oBAAoB,GAAG,OAAO,EACzC,MAAM,EACN,QAAQ,GAIT,KAAmB;AAClB,IAAA,MAAM,aAAa,GAAG,MAAM,KAAK,CAC/B,CAAA,EAAG,MAAM,CAAC,aAAa,CAAA,UAAA,EAAa,QAAQ,CAAA,CAAE,EAC9C;AACE,QAAA,MAAM,EAAE,KAAK;AACb,QAAA,OAAO,EAAE;AACP,YAAA,cAAc,EAAE,kBAAkB;AACnC,SAAA;AACF,KAAA,CACF;AAED,IAAA,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE;AACrB,QAAA,IAAI,gBAAgB;AAEpB,QAAA,IAAI;AACF,YAAA,gBAAgB,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE;QAC/C;AAAE,QAAA,MAAM;AACN,YAAA,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC;QACpE;AAEA,QAAA,MAAM,IAAI,gBAAgB,CACxB,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAC3B,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAC/B;IACH;AACF;;;;"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { useUser } from './useUser';
@@ -0,0 +1,9 @@
1
+ import { Auth0Config, EnrichedSessionUser } from 'src/types';
2
+ export declare const useUser: ({ config }: {
3
+ config: Auth0Config;
4
+ }) => {
5
+ user: EnrichedSessionUser | null;
6
+ error: Error | null;
7
+ isLoading: boolean;
8
+ invalidate: () => Promise<EnrichedSessionUser | undefined>;
9
+ };
@@ -0,0 +1,24 @@
1
+ "use client";
2
+ import useSWR from 'swr';
3
+ import { useCallback } from 'react';
4
+
5
+ const userFetcher = async (url) => {
6
+ const response = await fetch(url);
7
+ if (!response.ok) {
8
+ throw new Error('Unauthorized');
9
+ }
10
+ return response.json();
11
+ };
12
+ const useUser = ({ config }) => {
13
+ const { data, error, isLoading, mutate } = useSWR(config.userProfileEndpoint, userFetcher);
14
+ const invalidate = useCallback(() => mutate(), [mutate]);
15
+ return {
16
+ user: data ?? null,
17
+ error: error ?? null,
18
+ isLoading,
19
+ invalidate,
20
+ };
21
+ };
22
+
23
+ export { useUser };
24
+ //# sourceMappingURL=useUser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUser.js","sources":["../../../../../src/client/hooks/useUser.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAOA;AACE;AACA;AACE;;AAGF;AACF;;AAGE;AAMA;;;;;;;AAQF;;"}
@@ -0,0 +1,2 @@
1
+ export * from './client/helpers';
2
+ export * from './client/hooks';
package/dist/esm/index.js CHANGED
@@ -1,2 +1,4 @@
1
- "use strict";
1
+ export { getAccessToken } from './client/helpers/getAccessToken.js';
2
+ export { switchSelectedTenant } from './client/helpers/switchSelectedTenant.js';
3
+ export { useUser } from './client/hooks/useUser.js';
2
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -1,5 +1,5 @@
1
1
  import { Auth0Client } from '@auth0/nextjs-auth0/server';
2
- type GetAuth0InstanceContext = {
2
+ export type GetAuth0InstanceContext = {
3
3
  protocol: string;
4
4
  host: string;
5
5
  isProxied: boolean;
@@ -7,4 +7,3 @@ type GetAuth0InstanceContext = {
7
7
  export declare const getAuth0Instance: ({ protocol, host, isProxied, onError, }: GetAuth0InstanceContext & {
8
8
  onError?: (error: Error) => void;
9
9
  }) => Auth0Client;
10
- export {};
@@ -0,0 +1,2 @@
1
+ import { GetAuth0InstanceContext } from '../getAuth0Instance';
2
+ export declare const getAccessToken: (context: GetAuth0InstanceContext) => Promise<string>;
@@ -0,0 +1,10 @@
1
+ import { getAuth0Instance } from '../getAuth0Instance.js';
2
+
3
+ const getAccessToken = async (context) => {
4
+ const auth0Instance = getAuth0Instance(context);
5
+ const { token } = await auth0Instance.getAccessToken();
6
+ return token;
7
+ };
8
+
9
+ export { getAccessToken };
10
+ //# sourceMappingURL=getAccessToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getAccessToken.js","sources":["../../../../../src/server/helpers/getAccessToken.ts"],"sourcesContent":[null],"names":[],"mappings":";;MAEa,cAAc,GAAG,OAAO,OAAgC,KAAI;AACvE,IAAA,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,CAAC;IAC/C,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,aAAa,CAAC,cAAc,EAAE;AACtD,IAAA,OAAO,KAAK;AACd;;;;"}
@@ -0,0 +1,3 @@
1
+ import { SessionUser } from 'src/types';
2
+ import { GetAuth0InstanceContext } from '../getAuth0Instance';
3
+ export declare const getUser: (context: GetAuth0InstanceContext) => Promise<SessionUser | null>;
@@ -0,0 +1,12 @@
1
+ import { getAuth0Instance } from '../getAuth0Instance.js';
2
+
3
+ const getUser = async (context) => {
4
+ const auth0Instance = getAuth0Instance(context);
5
+ const sessionData = await auth0Instance.getSession();
6
+ if (!sessionData || !sessionData.user)
7
+ return null;
8
+ return sessionData.user;
9
+ };
10
+
11
+ export { getUser };
12
+ //# sourceMappingURL=getUser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUser.js","sources":["../../../../../src/server/helpers/getUser.ts"],"sourcesContent":[null],"names":[],"mappings":";;MAIa,OAAO,GAAG,OACrB,OAAgC,KACD;AAC/B,IAAA,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,CAAC;AAC/C,IAAA,MAAM,WAAW,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE;AAEpD,IAAA,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,IAAI;AAAE,QAAA,OAAO,IAAI;IAElD,OAAO,WAAW,CAAC,IAAmB;AACxC;;;;"}
@@ -0,0 +1,3 @@
1
+ export { getAccessToken } from './getAccessToken';
2
+ export { getUser } from './getUser';
3
+ export { isLoggedIn } from './isLoggedIn';
@@ -0,0 +1,2 @@
1
+ import { GetAuth0InstanceContext } from '../getAuth0Instance';
2
+ export declare const isLoggedIn: (context: GetAuth0InstanceContext) => Promise<boolean>;
@@ -0,0 +1,9 @@
1
+ import { getUser } from './getUser.js';
2
+
3
+ const isLoggedIn = async (context) => {
4
+ const user = await getUser(context);
5
+ return !!user;
6
+ };
7
+
8
+ export { isLoggedIn };
9
+ //# sourceMappingURL=isLoggedIn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isLoggedIn.js","sources":["../../../../../src/server/helpers/isLoggedIn.ts"],"sourcesContent":[null],"names":[],"mappings":";;MAGa,UAAU,GAAG,OAAO,OAAgC,KAAI;AACnE,IAAA,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC;IACnC,OAAO,CAAC,CAAC,IAAI;AACf;;;;"}
@@ -1 +1,2 @@
1
- export { authMiddleware } from './server/middleware';
1
+ export * from './server/middleware';
2
+ export * from './server/helpers';
@@ -1,2 +1,5 @@
1
1
  export { authMiddleware } from './server/middleware/index.js';
2
+ export { getAccessToken } from './server/helpers/getAccessToken.js';
3
+ export { getUser } from './server/helpers/getUser.js';
4
+ export { isLoggedIn } from './server/helpers/isLoggedIn.js';
2
5
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
1
+ {"version":3,"file":"server.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -1,86 +1,9 @@
1
- import { Language } from '@smg-automotive/i18n-pkg';
2
-
3
- type CookieOptions = {
4
- name: string;
5
- httpOnly: boolean;
6
- maxAge: number;
7
- secure: boolean;
8
- sameSite: boolean | 'lax' | 'strict' | 'none' | undefined;
9
- path: string;
10
- };
11
-
12
- type Auth0Config = {
13
- loginEndpoint: string;
14
- logoutEndpoint: string;
15
- tokenEndpoint: string;
16
- callbackEndpoint: string;
17
- userProfileEndpoint: string;
18
- intervalDelayInMs: number;
19
- refreshThresholdInMs: number;
20
- selectedSellerIdCookie: CookieOptions;
21
- impersonatedSellerIdCookie: CookieOptions;
22
- proxyPathSegment: string;
23
- legacyAccessTokenName: string;
24
- legacyRefreshTokenName: string;
25
- providerInterval: number;
26
- debugForceTokenRefresh: boolean;
27
- languageConfig: {
28
- default: Language;
29
- supported: Language[];
30
- };
31
- scopes: string;
32
- globalAuthErrorPath: string;
33
- authCookieNames: string[];
34
- sessionCookieName: string;
35
- audience: string;
36
- };
37
-
38
- declare enum Auth0UserType {
39
- Private = "private",
40
- Professional = "professional"
41
- }
42
- type Auth0User = {
43
- email: string;
44
- email_verified: boolean;
45
- sub: string;
46
- };
1
+ import { A as Auth0Config } from './config-U4mojGmR.js';
2
+ import { E as EnrichedSessionUser, a as Entitlements } from './sessionUser-cqv4vnLO.js';
3
+ import '@smg-automotive/i18n-pkg';
47
4
 
48
5
  declare const authConfig: (args?: Partial<Auth0Config>) => Auth0Config;
49
6
 
50
- type ManagedSeller = {
51
- id: number;
52
- billingAddress: string | null;
53
- billingCity: string | null;
54
- billingCountryCode: string | null;
55
- billingName: string | null;
56
- billingPostOfficeBox: string | null;
57
- billingZipCode: string | null;
58
- };
59
-
60
- type EntitlementsEntry = {
61
- maxItems: number;
62
- remainingItems: number | null;
63
- };
64
- type Entitlement = {
65
- global: EntitlementsEntry;
66
- listings: Record<number, EntitlementsEntry>;
67
- usageDuration?: number;
68
- };
69
- type Entitlements = Record<string, Entitlement>;
70
-
71
- type SessionUser = Auth0User & {
72
- isImpersonated: boolean;
73
- forceTenantSelection: boolean;
74
- isMultiTenantUser: boolean;
75
- userId: string;
76
- sellerId: string;
77
- userType: Auth0UserType;
78
- };
79
- type EnrichedSessionUser = SessionUser & {
80
- entitlements: Entitlements | null;
81
- managedSellers: ManagedSeller[];
82
- };
83
-
84
7
  declare const privateUser: (props?: Partial<Exclude<EnrichedSessionUser, "userType" | "isMultiTenantUser">>) => EnrichedSessionUser;
85
8
  declare const professionalUser: (props?: Partial<Exclude<EnrichedSessionUser, "userType">>) => EnrichedSessionUser;
86
9
  declare const multiTenantUser: (props?: Partial<Exclude<EnrichedSessionUser, "userType" | "isMultiTenantUser">>) => EnrichedSessionUser;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,23 @@
1
+ import { A as Auth0Config } from './config-U4mojGmR.js';
2
+ import { E as EnrichedSessionUser } from './sessionUser-cqv4vnLO.js';
3
+ import '@smg-automotive/i18n-pkg';
1
4
 
2
- export { };
5
+ declare const getAccessToken: ({ config }: {
6
+ config: Auth0Config;
7
+ }) => Promise<any>;
8
+
9
+ declare const switchSelectedTenant: ({ config, sellerId, }: {
10
+ config: Auth0Config;
11
+ sellerId: string;
12
+ }) => Promise<void>;
13
+
14
+ declare const useUser: ({ config }: {
15
+ config: Auth0Config;
16
+ }) => {
17
+ user: EnrichedSessionUser | null;
18
+ error: Error | null;
19
+ isLoading: boolean;
20
+ invalidate: () => Promise<EnrichedSessionUser | undefined>;
21
+ };
22
+
23
+ export { getAccessToken, switchSelectedTenant, useUser };
package/dist/server.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
2
  import { Language } from '@smg-automotive/i18n-pkg';
3
+ import { S as SessionUser } from './sessionUser-cqv4vnLO.js';
3
4
 
4
5
  declare enum Brand {
5
6
  AutoScout24 = "autoscout24",
@@ -17,4 +18,16 @@ declare const authMiddleware: ({ request, isProtectedRoute, language, host, prot
17
18
  brand: Brand;
18
19
  }) => Promise<NextResponse>;
19
20
 
20
- export { authMiddleware };
21
+ type GetAuth0InstanceContext = {
22
+ protocol: string;
23
+ host: string;
24
+ isProxied: boolean;
25
+ };
26
+
27
+ declare const getAccessToken: (context: GetAuth0InstanceContext) => Promise<string>;
28
+
29
+ declare const getUser: (context: GetAuth0InstanceContext) => Promise<SessionUser | null>;
30
+
31
+ declare const isLoggedIn: (context: GetAuth0InstanceContext) => Promise<boolean>;
32
+
33
+ export { authMiddleware, getAccessToken, getUser, isLoggedIn };
@@ -0,0 +1,45 @@
1
+ declare enum Auth0UserType {
2
+ Private = "private",
3
+ Professional = "professional"
4
+ }
5
+ type Auth0User = {
6
+ email: string;
7
+ email_verified: boolean;
8
+ sub: string;
9
+ };
10
+
11
+ type ManagedSeller = {
12
+ id: number;
13
+ billingAddress: string | null;
14
+ billingCity: string | null;
15
+ billingCountryCode: string | null;
16
+ billingName: string | null;
17
+ billingPostOfficeBox: string | null;
18
+ billingZipCode: string | null;
19
+ };
20
+
21
+ type EntitlementsEntry = {
22
+ maxItems: number;
23
+ remainingItems: number | null;
24
+ };
25
+ type Entitlement = {
26
+ global: EntitlementsEntry;
27
+ listings: Record<number, EntitlementsEntry>;
28
+ usageDuration?: number;
29
+ };
30
+ type Entitlements = Record<string, Entitlement>;
31
+
32
+ type SessionUser = Auth0User & {
33
+ isImpersonated: boolean;
34
+ forceTenantSelection: boolean;
35
+ isMultiTenantUser: boolean;
36
+ userId: string;
37
+ sellerId: string;
38
+ userType: Auth0UserType;
39
+ };
40
+ type EnrichedSessionUser = SessionUser & {
41
+ entitlements: Entitlements | null;
42
+ managedSellers: ManagedSeller[];
43
+ };
44
+
45
+ export type { EnrichedSessionUser as E, SessionUser as S, Entitlements as a };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smg-automotive/auth",
3
- "version": "6.8.0-auth0-update-root.9",
3
+ "version": "6.8.0-auth0-update-switch-tenant.2",
4
4
  "description": "SMG Automotive auth package",
5
5
  "exports": {
6
6
  ".": {
@@ -64,6 +64,7 @@
64
64
  "dotenv": "17.2.1",
65
65
  "jest": "30.0.5",
66
66
  "jest-environment-jsdom": "30.0.5",
67
+ "jest-fetch-mock": "3.0.3",
67
68
  "next": "15.5.0",
68
69
  "react": "18.3.1",
69
70
  "react-dom": "18.3.1",
@@ -73,6 +74,7 @@
73
74
  "rollup-plugin-peer-deps-external": "2.2.4",
74
75
  "rollup-plugin-preserve-directives": "0.4.0",
75
76
  "semantic-release": "24.2.7",
77
+ "swr": "2.3.6",
76
78
  "ts-jest": "29.4.1",
77
79
  "ts-node": "10.9.2",
78
80
  "typescript": "5.9.2",
@@ -85,8 +87,9 @@
85
87
  "jose": "6.0.12"
86
88
  },
87
89
  "peerDependencies": {
88
- "next": ">= 13.0.0",
89
- "react": ">= 18.0.0",
90
- "react-dom": ">= 18.0.0"
90
+ "next": "^15.0.0",
91
+ "react": "^19.0.0",
92
+ "react-dom": "^19.0.0",
93
+ "swr": "^2.0.0"
91
94
  }
92
95
  }