@smg-automotive/auth 8.4.1 → 8.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -74
- package/dist/cjs/server/helpers/getAccessToken.d.ts +1 -2
- package/dist/cjs/server/helpers/getAccessToken.js +3 -9
- package/dist/cjs/server/helpers/getAccessToken.js.map +1 -1
- package/dist/cjs/server/helpers/getAuthProps.d.ts +0 -6
- package/dist/cjs/server/helpers/getAuthProps.js.map +1 -1
- package/dist/cjs/server/helpers/getUser.d.ts +2 -3
- package/dist/cjs/server/helpers/getUser.js +7 -14
- package/dist/cjs/server/helpers/getUser.js.map +1 -1
- package/dist/cjs/server/helpers/isLoggedIn.d.ts +1 -2
- package/dist/cjs/server/helpers/isLoggedIn.js.map +1 -1
- package/dist/esm/server/helpers/getAccessToken.d.ts +1 -2
- package/dist/esm/server/helpers/getAccessToken.js +3 -9
- package/dist/esm/server/helpers/getAccessToken.js.map +1 -1
- package/dist/esm/server/helpers/getAuthProps.d.ts +0 -6
- package/dist/esm/server/helpers/getAuthProps.js.map +1 -1
- package/dist/esm/server/helpers/getUser.d.ts +2 -3
- package/dist/esm/server/helpers/getUser.js +7 -14
- package/dist/esm/server/helpers/getUser.js.map +1 -1
- package/dist/esm/server/helpers/isLoggedIn.d.ts +1 -2
- package/dist/esm/server/helpers/isLoggedIn.js.map +1 -1
- package/dist/server.d.ts +3 -16
- package/package.json +2 -2
- package/dist/cjs/types/serverRequestContext.d.ts +0 -8
- package/dist/esm/types/serverRequestContext.d.ts +0 -8
package/README.md
CHANGED
|
@@ -60,78 +60,13 @@ export const config = { runtime: "nodejs" };
|
|
|
60
60
|
|
|
61
61
|
This package exposes the `AuthProvider`. It exposes the auth configuration and pre-caches the user data.
|
|
62
62
|
|
|
63
|
-
You want to include the `AuthProvider` on the top level of your application and supply the props obtained server-side from auth0.
|
|
63
|
+
You want to include the `AuthProvider` on the top level of your application and supply the props obtained server-side from auth0. `getAuthProps` handles fetching those props for the Next.js app router.
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
We rely on `PageProps` combined with `getInitialProps` to pass the auth props to your `App` component.
|
|
68
|
-
|
|
69
|
-
```tsx
|
|
70
|
-
// src/pages/_app.tsx
|
|
71
|
-
import App, { type AppContext, type AppProps } from 'next/app';
|
|
72
|
-
import { type AuthProviderProps, AuthProvider } from '@smg-automotive/auth';
|
|
73
|
-
|
|
74
|
-
type PageProps = {
|
|
75
|
-
// your other page props
|
|
76
|
-
authProps: AuthProviderProps;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const MyApp = ({
|
|
80
|
-
Component,
|
|
81
|
-
pageProps: { authProps, ...pageProps },
|
|
82
|
-
}: AppProps<PageProps>) => {
|
|
83
|
-
return (
|
|
84
|
-
<AuthProvider {...authProps} language={pageProps.language}>
|
|
85
|
-
<Component {...pageProps} />
|
|
86
|
-
</AuthProvider>
|
|
87
|
-
);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
MyApp.getInitialProps = async (appContext: AppContext) => {
|
|
91
|
-
const appProps = await App.getInitialProps(appContext);
|
|
92
|
-
const request = appContext.ctx.req;
|
|
93
|
-
const response = appContext.ctx.res;
|
|
94
|
-
|
|
95
|
-
const brand = yourBrandDerivingLogic();
|
|
96
|
-
const language = yourLanguageDerivingLogic();
|
|
97
|
-
const protocol = yourProtocolDetectionLogic();
|
|
98
|
-
const host = yourHostDetectionLogic();
|
|
99
|
-
|
|
100
|
-
const { getAuthProps } = await import(
|
|
101
|
-
'@smg-automotive/auth/server'
|
|
102
|
-
);
|
|
103
|
-
const authProps = await getAuthProps({
|
|
104
|
-
brand,
|
|
105
|
-
protocol,
|
|
106
|
-
host,
|
|
107
|
-
context: {
|
|
108
|
-
request,
|
|
109
|
-
response,
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
Object.assign(appProps.pageProps, {
|
|
114
|
-
...pageProps,
|
|
115
|
-
authProps,
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
return appProps;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
export default MyApp;
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
The `getServerAuthPropsPages` function will:
|
|
125
|
-
|
|
126
|
-
- get the required auth props from the request
|
|
127
|
-
- handle the redirect to the login page if refreshing auth token is not possible
|
|
128
|
-
- extend the app props with the auth props and your custom page props and return them
|
|
129
|
-
|
|
130
|
-
You can pass an `errorHandler` of your choice to the `AuthProvider` to handle errors.
|
|
65
|
+
> Pages router support has been removed. Use the app router with `getAuthProps`.
|
|
131
66
|
|
|
132
67
|
#### App Router
|
|
133
68
|
|
|
134
|
-
|
|
69
|
+
Use `getAuthProps` in your layout (or other server components) and pass the result to the `AuthProvider`.
|
|
135
70
|
|
|
136
71
|
```tsx
|
|
137
72
|
// src/app/layout.tsx
|
|
@@ -146,11 +81,7 @@ const Layout: FC<PropsWithChildren> = ({ children }) => {
|
|
|
146
81
|
const protocol = yourProtocolDetectionLogic();
|
|
147
82
|
const host = yourHostDetectionLogic();
|
|
148
83
|
|
|
149
|
-
const authProps = await getAuthProps({
|
|
150
|
-
brand,
|
|
151
|
-
protocol,
|
|
152
|
-
host,
|
|
153
|
-
});
|
|
84
|
+
const authProps = await getAuthProps({ brand, protocol, host });
|
|
154
85
|
|
|
155
86
|
return (
|
|
156
87
|
<AuthProvider brand={brand} language={language} {...authProps}>
|
|
@@ -160,7 +91,7 @@ const Layout: FC<PropsWithChildren> = ({ children }) => {
|
|
|
160
91
|
};
|
|
161
92
|
```
|
|
162
93
|
|
|
163
|
-
|
|
94
|
+
`getAuthProps` will handle the redirect to the login page if refreshing the auth token is not possible.
|
|
164
95
|
|
|
165
96
|
You can pass an `errorHandler` of your choice to the `AuthProvider` to handle errors. Since the provider is a client component you need to mark it as a server action.
|
|
166
97
|
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { ServerRequestContext } from 'src/types/serverRequestContext';
|
|
2
1
|
import { GetAuth0InstanceContext } from '../getAuth0Instance';
|
|
3
|
-
export declare const getAccessToken: ({ protocol, host,
|
|
2
|
+
export declare const getAccessToken: ({ protocol, host, }: GetAuth0InstanceContext) => Promise<string>;
|
|
@@ -8,16 +8,10 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
8
8
|
var debug__default = /*#__PURE__*/_interopDefaultCompat(debug);
|
|
9
9
|
|
|
10
10
|
const log = debug__default.default('@smg-automotive/auth:token');
|
|
11
|
-
const getAccessToken = async ({ protocol, host,
|
|
12
|
-
log('Getting access token', {
|
|
13
|
-
host,
|
|
14
|
-
protocol,
|
|
15
|
-
hasRequest: !!context?.request,
|
|
16
|
-
});
|
|
11
|
+
const getAccessToken = async ({ protocol, host, }) => {
|
|
12
|
+
log('Getting access token', { host, protocol });
|
|
17
13
|
const auth0Instance = getAuth0Instance.getAuth0Instance({ protocol, host });
|
|
18
|
-
const { token } =
|
|
19
|
-
? await auth0Instance.getAccessToken(context.request, context.response)
|
|
20
|
-
: await auth0Instance.getAccessToken();
|
|
14
|
+
const { token } = await auth0Instance.getAccessToken();
|
|
21
15
|
log('Access token retrieved', { tokenLength: token?.length || 0 });
|
|
22
16
|
return token;
|
|
23
17
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAccessToken.js","sources":["../../../../../src/server/helpers/getAccessToken.ts"],"sourcesContent":[null],"names":["debug","getAuth0Instance"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"getAccessToken.js","sources":["../../../../../src/server/helpers/getAccessToken.ts"],"sourcesContent":[null],"names":["debug","getAuth0Instance"],"mappings":";;;;;;;;;AAIA,MAAM,GAAG,GAAGA,sBAAK,CAAC,4BAA4B,CAAC;AAExC,MAAM,cAAc,GAAG,OAAO,EACnC,QAAQ,EACR,IAAI,GACoB,KAAI;IAC5B,GAAG,CAAC,sBAAsB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAE/C,MAAM,aAAa,GAAGC,iCAAgB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC1D,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,aAAa,CAAC,cAAc,EAAE;AACtD,IAAA,GAAG,CAAC,wBAAwB,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC,EAAE,CAAC;AAClE,IAAA,OAAO,KAAK;AACd;;;;"}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
1
|
import { Brand } from 'src/types/brand';
|
|
4
2
|
import { AuthProviderProps } from 'src/client/contexts/Auth';
|
|
5
3
|
import { GetAuth0InstanceContext } from '../getAuth0Instance';
|
|
6
4
|
export declare const getAuthProps: (context: GetAuth0InstanceContext & {
|
|
7
5
|
brand: Brand;
|
|
8
|
-
context?: {
|
|
9
|
-
request: NextApiRequest | IncomingMessage;
|
|
10
|
-
response: NextApiResponse | ServerResponse<IncomingMessage>;
|
|
11
|
-
};
|
|
12
6
|
}) => Promise<AuthProviderProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAuthProps.js","sources":["../../../../../src/server/helpers/getAuthProps.ts"],"sourcesContent":[null],"names":["debug","getAuth0Config","getEnrichedUser"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"getAuthProps.js","sources":["../../../../../src/server/helpers/getAuthProps.ts"],"sourcesContent":[null],"names":["debug","getAuth0Config","getEnrichedUser"],"mappings":";;;;;;;;;;AASA,MAAM,GAAG,GAAGA,sBAAK,CAAC,2BAA2B,CAAC;MAEjC,YAAY,GAAG,OAC1B,OAEC,KAC6B;AAC9B,IAAA,MAAM,WAAW,GAAGC,oBAAc,EAAE;IAEpC,IAAI,IAAI,GAAG,IAAI;AACf,IAAA,IAAI;AACF,QAAA,IAAI,GAAG,MAAMC,uBAAe,CAAC,OAAO,CAAC;IACvC;IAAE,OAAO,KAAK,EAAE;AACd,QAAA,GAAG,CAAC,uBAAuB,EAAE,KAAK,CAAC;IACrC;AAEA,IAAA,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE;AAC9B;;;;"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { ServerRequestContext } from 'src/types/serverRequestContext';
|
|
2
1
|
import { Brand } from 'src/types/brand';
|
|
3
2
|
import { EnrichedSessionUser, SessionUser } from 'src/types';
|
|
4
3
|
import { GetAuth0InstanceContext } from 'src/server/getAuth0Instance';
|
|
5
|
-
export declare const getUser: ({
|
|
6
|
-
export declare const getEnrichedUser: ({ brand,
|
|
4
|
+
export declare const getUser: ({ host, protocol, }: GetAuth0InstanceContext) => Promise<SessionUser | null>;
|
|
5
|
+
export declare const getEnrichedUser: ({ brand, host, protocol, }: GetAuth0InstanceContext & {
|
|
7
6
|
brand: Brand;
|
|
8
7
|
}) => Promise<EnrichedSessionUser | null>;
|
|
@@ -10,22 +10,16 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
10
10
|
var debug__default = /*#__PURE__*/_interopDefaultCompat(debug);
|
|
11
11
|
|
|
12
12
|
const log = debug__default.default('@smg-automotive/auth:user');
|
|
13
|
-
const getSessionData = async ({ protocol, host
|
|
14
|
-
log('Retrieving session data', {
|
|
15
|
-
host,
|
|
16
|
-
protocol,
|
|
17
|
-
hasRequest: !!context?.request,
|
|
18
|
-
});
|
|
13
|
+
const getSessionData = async ({ protocol, host }) => {
|
|
14
|
+
log('Retrieving session data', { host, protocol });
|
|
19
15
|
const auth0Instance = getAuth0Instance.getAuth0Instance({ host, protocol });
|
|
20
|
-
const session =
|
|
21
|
-
? await auth0Instance.getSession(context.request)
|
|
22
|
-
: await auth0Instance.getSession();
|
|
16
|
+
const session = await auth0Instance.getSession();
|
|
23
17
|
log('Session retrieved', { hasSession: !!session, hasUser: !!session?.user });
|
|
24
18
|
return session;
|
|
25
19
|
};
|
|
26
|
-
const getUser = async ({
|
|
20
|
+
const getUser = async ({ host, protocol, }) => {
|
|
27
21
|
log('Getting user', { host, protocol });
|
|
28
|
-
const sessionData = await getSessionData({ host, protocol
|
|
22
|
+
const sessionData = await getSessionData({ host, protocol });
|
|
29
23
|
if (!sessionData || !sessionData.user) {
|
|
30
24
|
log('No session or user found');
|
|
31
25
|
return null;
|
|
@@ -37,9 +31,9 @@ const getUser = async ({ context, host, protocol, }) => {
|
|
|
37
31
|
});
|
|
38
32
|
return user;
|
|
39
33
|
};
|
|
40
|
-
const getEnrichedUser = async ({ brand,
|
|
34
|
+
const getEnrichedUser = async ({ brand, host, protocol, }) => {
|
|
41
35
|
log('Getting enriched user', { brand, host, protocol });
|
|
42
|
-
const user = await getUser({ host, protocol
|
|
36
|
+
const user = await getUser({ host, protocol });
|
|
43
37
|
if (!user) {
|
|
44
38
|
log('No user found, cannot enrich');
|
|
45
39
|
return null;
|
|
@@ -48,7 +42,6 @@ const getEnrichedUser = async ({ brand, context, host, protocol, }) => {
|
|
|
48
42
|
const accessToken = await getAccessToken.getAccessToken({
|
|
49
43
|
host,
|
|
50
44
|
protocol,
|
|
51
|
-
context,
|
|
52
45
|
});
|
|
53
46
|
log('Access token retrieved, enriching user');
|
|
54
47
|
const enrichedUser = await session.enrichUser({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getUser.js","sources":["../../../../../src/server/helpers/getUser.ts"],"sourcesContent":[null],"names":["debug","getAuth0Instance","getAccessToken","enrichUser"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"getUser.js","sources":["../../../../../src/server/helpers/getUser.ts"],"sourcesContent":[null],"names":["debug","getAuth0Instance","getAccessToken","enrichUser"],"mappings":";;;;;;;;;;;AAWA,MAAM,GAAG,GAAGA,sBAAK,CAAC,2BAA2B,CAAC;AAE9C,MAAM,cAAc,GAAG,OAAO,EAAE,QAAQ,EAAE,IAAI,EAA2B,KAAI;IAC3E,GAAG,CAA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AAI;IACb;IAEA,GAAG,CAAC,wCAAwC,CAAC;AAC7C,IAAA,MAAM,WAAW,GAAG,MAAMC,6BAAc,CAAC;QACvC,IAAI;QACJ,QAAQ;AACT,KAAA,CAAC;IACF,GAAG,CAAC,wCAAwC,CAAC;AAC7C,IAAA,MAAM,YAAY,GAAG,MAAMC,kBAAU,CAAC;QACpC,IAAI;QACJ,WAAW;QACX,KAAK;AACN,KAAA,CAAC;IACF,GAAG,CAAC,4BAA4B,EAAE;QAChC,MAAM,EAAE,YAAY,CAAC,MAAM;QAC3B,QAAQ,EAAE,YAAY,CAAC,QAAQ;AAC/B,QAAA,eAAe,EAAE,CAAC,CAAC,YAAY,CAAC,YAAY;AAC7C,KAAA,CAAC;AACF,IAAA,OAAO,YAAY;AACrB;;;;;"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { ServerRequestContext } from 'src/types/serverRequestContext';
|
|
2
1
|
import { GetAuth0InstanceContext } from '../getAuth0Instance';
|
|
3
|
-
export declare const isLoggedIn: (context: GetAuth0InstanceContext
|
|
2
|
+
export declare const isLoggedIn: (context: GetAuth0InstanceContext) => Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isLoggedIn.js","sources":["../../../../../src/server/helpers/isLoggedIn.ts"],"sourcesContent":[null],"names":["getUser"],"mappings":";;;;
|
|
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,3 +1,2 @@
|
|
|
1
|
-
import { ServerRequestContext } from 'src/types/serverRequestContext';
|
|
2
1
|
import { GetAuth0InstanceContext } from '../getAuth0Instance';
|
|
3
|
-
export declare const getAccessToken: ({ protocol, host,
|
|
2
|
+
export declare const getAccessToken: ({ protocol, host, }: GetAuth0InstanceContext) => Promise<string>;
|
|
@@ -2,16 +2,10 @@ import debug from 'debug';
|
|
|
2
2
|
import { getAuth0Instance } from '../getAuth0Instance.js';
|
|
3
3
|
|
|
4
4
|
const log = debug('@smg-automotive/auth:token');
|
|
5
|
-
const getAccessToken = async ({ protocol, host,
|
|
6
|
-
log('Getting access token', {
|
|
7
|
-
host,
|
|
8
|
-
protocol,
|
|
9
|
-
hasRequest: !!context?.request,
|
|
10
|
-
});
|
|
5
|
+
const getAccessToken = async ({ protocol, host, }) => {
|
|
6
|
+
log('Getting access token', { host, protocol });
|
|
11
7
|
const auth0Instance = getAuth0Instance({ protocol, host });
|
|
12
|
-
const { token } =
|
|
13
|
-
? await auth0Instance.getAccessToken(context.request, context.response)
|
|
14
|
-
: await auth0Instance.getAccessToken();
|
|
8
|
+
const { token } = await auth0Instance.getAccessToken();
|
|
15
9
|
log('Access token retrieved', { tokenLength: token?.length || 0 });
|
|
16
10
|
return token;
|
|
17
11
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAccessToken.js","sources":["../../../../../src/server/helpers/getAccessToken.ts"],"sourcesContent":[null],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"getAccessToken.js","sources":["../../../../../src/server/helpers/getAccessToken.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAIA,MAAM,GAAG,GAAG,KAAK,CAAC,4BAA4B,CAAC;AAExC,MAAM,cAAc,GAAG,OAAO,EACnC,QAAQ,EACR,IAAI,GACoB,KAAI;IAC5B,GAAG,CAAC,sBAAsB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAE/C,MAAM,aAAa,GAAG,gBAAgB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC1D,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,aAAa,CAAC,cAAc,EAAE;AACtD,IAAA,GAAG,CAAC,wBAAwB,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC,EAAE,CAAC;AAClE,IAAA,OAAO,KAAK;AACd;;;;"}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
1
|
import { Brand } from 'src/types/brand';
|
|
4
2
|
import { AuthProviderProps } from 'src/client/contexts/Auth';
|
|
5
3
|
import { GetAuth0InstanceContext } from '../getAuth0Instance';
|
|
6
4
|
export declare const getAuthProps: (context: GetAuth0InstanceContext & {
|
|
7
5
|
brand: Brand;
|
|
8
|
-
context?: {
|
|
9
|
-
request: NextApiRequest | IncomingMessage;
|
|
10
|
-
response: NextApiResponse | ServerResponse<IncomingMessage>;
|
|
11
|
-
};
|
|
12
6
|
}) => Promise<AuthProviderProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAuthProps.js","sources":["../../../../../src/server/helpers/getAuthProps.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"getAuthProps.js","sources":["../../../../../src/server/helpers/getAuthProps.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AASA,MAAM,GAAG,GAAG,KAAK,CAAC,2BAA2B,CAAC;MAEjC,YAAY,GAAG,OAC1B,OAEC,KAC6B;AAC9B,IAAA,MAAM,WAAW,GAAG,cAAc,EAAE;IAEpC,IAAI,IAAI,GAAG,IAAI;AACf,IAAA,IAAI;AACF,QAAA,IAAI,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC;IACvC;IAAE,OAAO,KAAK,EAAE;AACd,QAAA,GAAG,CAAC,uBAAuB,EAAE,KAAK,CAAC;IACrC;AAEA,IAAA,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE;AAC9B;;;;"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { ServerRequestContext } from 'src/types/serverRequestContext';
|
|
2
1
|
import { Brand } from 'src/types/brand';
|
|
3
2
|
import { EnrichedSessionUser, SessionUser } from 'src/types';
|
|
4
3
|
import { GetAuth0InstanceContext } from 'src/server/getAuth0Instance';
|
|
5
|
-
export declare const getUser: ({
|
|
6
|
-
export declare const getEnrichedUser: ({ brand,
|
|
4
|
+
export declare const getUser: ({ host, protocol, }: GetAuth0InstanceContext) => Promise<SessionUser | null>;
|
|
5
|
+
export declare const getEnrichedUser: ({ brand, host, protocol, }: GetAuth0InstanceContext & {
|
|
7
6
|
brand: Brand;
|
|
8
7
|
}) => Promise<EnrichedSessionUser | null>;
|
|
@@ -4,22 +4,16 @@ import { getAuth0Instance } from '../getAuth0Instance.js';
|
|
|
4
4
|
import { enrichUser } from '../../lib/enrichUser/session.js';
|
|
5
5
|
|
|
6
6
|
const log = debug('@smg-automotive/auth:user');
|
|
7
|
-
const getSessionData = async ({ protocol, host
|
|
8
|
-
log('Retrieving session data', {
|
|
9
|
-
host,
|
|
10
|
-
protocol,
|
|
11
|
-
hasRequest: !!context?.request,
|
|
12
|
-
});
|
|
7
|
+
const getSessionData = async ({ protocol, host }) => {
|
|
8
|
+
log('Retrieving session data', { host, protocol });
|
|
13
9
|
const auth0Instance = getAuth0Instance({ host, protocol });
|
|
14
|
-
const session =
|
|
15
|
-
? await auth0Instance.getSession(context.request)
|
|
16
|
-
: await auth0Instance.getSession();
|
|
10
|
+
const session = await auth0Instance.getSession();
|
|
17
11
|
log('Session retrieved', { hasSession: !!session, hasUser: !!session?.user });
|
|
18
12
|
return session;
|
|
19
13
|
};
|
|
20
|
-
const getUser = async ({
|
|
14
|
+
const getUser = async ({ host, protocol, }) => {
|
|
21
15
|
log('Getting user', { host, protocol });
|
|
22
|
-
const sessionData = await getSessionData({ host, protocol
|
|
16
|
+
const sessionData = await getSessionData({ host, protocol });
|
|
23
17
|
if (!sessionData || !sessionData.user) {
|
|
24
18
|
log('No session or user found');
|
|
25
19
|
return null;
|
|
@@ -31,9 +25,9 @@ const getUser = async ({ context, host, protocol, }) => {
|
|
|
31
25
|
});
|
|
32
26
|
return user;
|
|
33
27
|
};
|
|
34
|
-
const getEnrichedUser = async ({ brand,
|
|
28
|
+
const getEnrichedUser = async ({ brand, host, protocol, }) => {
|
|
35
29
|
log('Getting enriched user', { brand, host, protocol });
|
|
36
|
-
const user = await getUser({ host, protocol
|
|
30
|
+
const user = await getUser({ host, protocol });
|
|
37
31
|
if (!user) {
|
|
38
32
|
log('No user found, cannot enrich');
|
|
39
33
|
return null;
|
|
@@ -42,7 +36,6 @@ const getEnrichedUser = async ({ brand, context, host, protocol, }) => {
|
|
|
42
36
|
const accessToken = await getAccessToken({
|
|
43
37
|
host,
|
|
44
38
|
protocol,
|
|
45
|
-
context,
|
|
46
39
|
});
|
|
47
40
|
log('Access token retrieved, enriching user');
|
|
48
41
|
const enrichedUser = await enrichUser({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getUser.js","sources":["../../../../../src/server/helpers/getUser.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"getUser.js","sources":["../../../../../src/server/helpers/getUser.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAWA,MAAM,GAAG,GAAG,KAAK,CAAC,2BAA2B,CAAC;AAE9C,MAAM,cAAc,GAAG,OAAO,EAAE,QAAQ,EAAE,IAAI,EAA2B,KAAI;IAC3E,GAAG,CAAC,yBAAyB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAClD,MAAM,aAAa,GAAG,gBAAgB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAE1D,IAAA,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE;AAEhD,IAAA,GAAG,CAAC,mBAAmB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC;AAC7E,IAAA,OAAO,OAAO;A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AAY,CAAC,QAAQ;AAC/B,QAAA,eAAe,EAAE,CAAC,CAAC,YAAY,CAAC,YAAY;AAC7C,KAAA,CAAC;AACF,IAAA,OAAO,YAAY;AACrB;;;;"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { ServerRequestContext } from 'src/types/serverRequestContext';
|
|
2
1
|
import { GetAuth0InstanceContext } from '../getAuth0Instance';
|
|
3
|
-
export declare const isLoggedIn: (context: GetAuth0InstanceContext
|
|
2
|
+
export declare const isLoggedIn: (context: GetAuth0InstanceContext) => Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isLoggedIn.js","sources":["../../../../../src/server/helpers/isLoggedIn.ts"],"sourcesContent":[null],"names":[],"mappings":";;
|
|
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;;;;"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import { Language } from '@smg-automotive/i18n-pkg';
|
|
3
|
-
import { NextApiRequest, NextApiResponse } from 'next';
|
|
4
|
-
import { IncomingMessage, ServerResponse } from 'http';
|
|
5
3
|
import { a as AuthProviderProps } from './Auth-C40nODjM.js';
|
|
6
4
|
import { S as SessionUser } from './sessionUser-wavMinWI.js';
|
|
7
5
|
import 'react';
|
|
@@ -21,30 +19,19 @@ declare const authMiddleware: ({ request, isProtectedRoute, language, host, prot
|
|
|
21
19
|
brand: Brand;
|
|
22
20
|
}) => Promise<NextResponse>;
|
|
23
21
|
|
|
24
|
-
type ServerRequestContext = {
|
|
25
|
-
context?: {
|
|
26
|
-
request: NextApiRequest | IncomingMessage;
|
|
27
|
-
response: NextApiResponse | ServerResponse<IncomingMessage>;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
|
|
31
22
|
type GetAuth0InstanceContext = {
|
|
32
23
|
protocol: string;
|
|
33
24
|
host: string;
|
|
34
25
|
};
|
|
35
26
|
|
|
36
|
-
declare const getAccessToken: ({ protocol, host,
|
|
27
|
+
declare const getAccessToken: ({ protocol, host, }: GetAuth0InstanceContext) => Promise<string>;
|
|
37
28
|
|
|
38
29
|
declare const getAuthProps: (context: GetAuth0InstanceContext & {
|
|
39
30
|
brand: Brand;
|
|
40
|
-
context?: {
|
|
41
|
-
request: NextApiRequest | IncomingMessage;
|
|
42
|
-
response: NextApiResponse | ServerResponse<IncomingMessage>;
|
|
43
|
-
};
|
|
44
31
|
}) => Promise<AuthProviderProps>;
|
|
45
32
|
|
|
46
|
-
declare const getUser: ({
|
|
33
|
+
declare const getUser: ({ host, protocol, }: GetAuth0InstanceContext) => Promise<SessionUser | null>;
|
|
47
34
|
|
|
48
|
-
declare const isLoggedIn: (context: GetAuth0InstanceContext
|
|
35
|
+
declare const isLoggedIn: (context: GetAuth0InstanceContext) => Promise<boolean>;
|
|
49
36
|
|
|
50
37
|
export { authMiddleware, getAccessToken, getAuthProps, getUser, isLoggedIn };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smg-automotive/auth",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.5.0",
|
|
4
4
|
"description": "SMG Automotive auth package",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"jest": "30.2.0",
|
|
75
75
|
"jest-environment-jsdom": "30.2.0",
|
|
76
76
|
"jest-fetch-mock": "3.0.3",
|
|
77
|
-
"next": "15.5.
|
|
77
|
+
"next": "15.5.8",
|
|
78
78
|
"react": "19.2.1",
|
|
79
79
|
"react-dom": "19.2.1",
|
|
80
80
|
"rimraf": "6.1.2",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
-
export type ServerRequestContext = {
|
|
4
|
-
context?: {
|
|
5
|
-
request: NextApiRequest | IncomingMessage;
|
|
6
|
-
response: NextApiResponse | ServerResponse<IncomingMessage>;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
-
export type ServerRequestContext = {
|
|
4
|
-
context?: {
|
|
5
|
-
request: NextApiRequest | IncomingMessage;
|
|
6
|
-
response: NextApiResponse | ServerResponse<IncomingMessage>;
|
|
7
|
-
};
|
|
8
|
-
};
|