@smg-automotive/auth 7.1.0-auth0-debug.2 → 7.1.0-auth0-debug.4
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/cjs/server/middleware/index.js +27 -1
- package/dist/cjs/server/middleware/index.js.map +1 -1
- package/dist/cjs/server/middleware/profile.d.ts +1 -2
- package/dist/cjs/server/middleware/profile.js +18 -9
- package/dist/cjs/server/middleware/profile.js.map +1 -1
- package/dist/esm/server/middleware/index.js +27 -1
- package/dist/esm/server/middleware/index.js.map +1 -1
- package/dist/esm/server/middleware/profile.d.ts +1 -2
- package/dist/esm/server/middleware/profile.js +18 -9
- package/dist/esm/server/middleware/profile.js.map +1 -1
- package/package.json +1 -1
|
@@ -22,6 +22,13 @@ const isAuthRoute = (pathname, auth0Config) => {
|
|
|
22
22
|
};
|
|
23
23
|
const authMiddleware = async ({ request, isProtectedRoute, language, host, protocol, onError, brand, }) => {
|
|
24
24
|
const { pathname } = request.nextUrl;
|
|
25
|
+
// eslint-disable-next-line no-console
|
|
26
|
+
console.debug({
|
|
27
|
+
message: 'authMiddleware: start',
|
|
28
|
+
pathname,
|
|
29
|
+
host,
|
|
30
|
+
protocol,
|
|
31
|
+
});
|
|
25
32
|
const auth0Instance = getAuth0Instance.getAuth0Instance({
|
|
26
33
|
host,
|
|
27
34
|
protocol,
|
|
@@ -34,6 +41,11 @@ const authMiddleware = async ({ request, isProtectedRoute, language, host, proto
|
|
|
34
41
|
request,
|
|
35
42
|
auth0Config,
|
|
36
43
|
});
|
|
44
|
+
// eslint-disable-next-line no-console
|
|
45
|
+
console.debug({
|
|
46
|
+
message: 'authMiddleware: crossDomainLogoutResult',
|
|
47
|
+
crossDomainLogoutResult: !!crossDomainLogoutResult,
|
|
48
|
+
});
|
|
37
49
|
if (crossDomainLogoutResult) {
|
|
38
50
|
return crossDomainLogoutResult;
|
|
39
51
|
}
|
|
@@ -55,16 +67,25 @@ const authMiddleware = async ({ request, isProtectedRoute, language, host, proto
|
|
|
55
67
|
auth0Config,
|
|
56
68
|
onError,
|
|
57
69
|
});
|
|
70
|
+
// eslint-disable-next-line no-console
|
|
71
|
+
console.debug({
|
|
72
|
+
message: 'authMiddleware: accessTokenRequestResult',
|
|
73
|
+
accessTokenRequestResult: !!accessTokenRequestResult,
|
|
74
|
+
});
|
|
58
75
|
if (accessTokenRequestResult) {
|
|
59
76
|
return accessTokenRequestResult;
|
|
60
77
|
}
|
|
61
78
|
const handleUserProfileResult = await profile.handleUserProfile({
|
|
62
79
|
request,
|
|
63
|
-
response: authResponse,
|
|
64
80
|
auth0Instance,
|
|
65
81
|
auth0Config,
|
|
66
82
|
brand,
|
|
67
83
|
});
|
|
84
|
+
// eslint-disable-next-line no-console
|
|
85
|
+
console.debug({
|
|
86
|
+
message: 'authMiddleware: handleUserProfileResult',
|
|
87
|
+
handleUserProfileResult: !!handleUserProfileResult,
|
|
88
|
+
});
|
|
68
89
|
if (handleUserProfileResult) {
|
|
69
90
|
return handleUserProfileResult;
|
|
70
91
|
}
|
|
@@ -81,6 +102,11 @@ const authMiddleware = async ({ request, isProtectedRoute, language, host, proto
|
|
|
81
102
|
response: authResponse,
|
|
82
103
|
onError,
|
|
83
104
|
});
|
|
105
|
+
// eslint-disable-next-line no-console
|
|
106
|
+
console.debug({
|
|
107
|
+
message: 'authMiddleware: protectRouteResult',
|
|
108
|
+
protectRouteResult: !!protectRouteResult,
|
|
109
|
+
});
|
|
84
110
|
if (protectRouteResult) {
|
|
85
111
|
return protectRouteResult;
|
|
86
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../src/server/middleware/index.ts"],"sourcesContent":[null],"names":["getAuth0Instance","getAuth0Config","handleCrossDomainLogout","addLoginParams","deleteRelatedSessionCookies","handleAccessTokenRequest","handleUserProfile","protectRoute","combineHeaders","NextResponse"],"mappings":";;;;;;;;;;;;AAeA,MAAM,WAAW,GAAG,CAAC,QAAgB,EAAE,WAAwB,KAAI;AACjE,IAAA,MAAM,EACJ,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,GACd,GAAG,WAAW;IAEf,OAAO;QACL,aAAa;QACb,cAAc;QACd,gBAAgB;QAChB,mBAAmB;QACnB,aAAa;AACd,KAAA,CAAC,QAAQ,CAAC,QAAQ,CAAC;AACtB,CAAC;MAEY,cAAc,GAAG,OAAO,EACnC,OAAO,EACP,gBAAgB,EAChB,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,KAAK,GASN,KAA2B;AAC1B,IAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,OAAO;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/server/middleware/index.ts"],"sourcesContent":[null],"names":["getAuth0Instance","getAuth0Config","handleCrossDomainLogout","addLoginParams","deleteRelatedSessionCookies","handleAccessTokenRequest","handleUserProfile","protectRoute","combineHeaders","NextResponse"],"mappings":";;;;;;;;;;;;AAeA,MAAM,WAAW,GAAG,CAAC,QAAgB,EAAE,WAAwB,KAAI;AACjE,IAAA,MAAM,EACJ,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,GACd,GAAG,WAAW;IAEf,OAAO;QACL,aAAa;QACb,cAAc;QACd,gBAAgB;QAChB,mBAAmB;QACnB,aAAa;AACd,KAAA,CAAC,QAAQ,CAAC,QAAQ,CAAC;AACtB,CAAC;MAEY,cAAc,GAAG,OAAO,EACnC,OAAO,EACP,gBAAgB,EAChB,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,KAAK,GASN,KAA2B;AAC1B,IAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,OAAO;;IAGpC,OAAO,CAAC,KAAK,CAAC;AACZ,QAAA,OAAO,EAAE,uBAAuB;QAChC,QAAQ;QACR,IAAI;QACJ,QAAQ;AACT,KAAA,CAAC;IAEF,MAAM,aAAa,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;QAClD,uBAAuB,EAAE,CAAC,CAAC,uBAAuB;AACnD,KAAA,CAAC;IACF,IAAI,uBAAuB,EAAE;AAC3B,QAAA,OAAO,uBAAuB;IAChC;IAEA,IAAI,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC,IAAI,gBAAgB,EAAE;AAC1D,QAAA,OAAO,YAAY;IACrB;IAEA,MAAM,WAAW,GAAG,CAAC,gBAAgB,IAAI,gBAAgB,CAAC,QAAQ,CAAC;AACnE,IAAA,MAAM,kBAAkB,GAAG,MAAMC,yBAAY,CAAC;QAC5C,WAAW;QACX,aAAa;QACb,WAAW;QACX,QAAQ;QACR,OAAO;AACP,QAAA,QAAQ,EAAE,YAAY;QACtB,OAAO;AACR,KAAA,CAAC;;IAEF,OAAO,CAAC,KAAK,CAAC;AACZ,QAAA,OAAO,EAAE,oCAAoC;QAC7C,kBAAkB,EAAE,CAAC,CAAC,kBAAkB;AACzC,KAAA,CAAC;IACF,IAAI,kBAAkB,EAAE;AACtB,QAAA,OAAO,kBAAkB;IAC3B;AAEA,IAAA,OAAOC,6BAAc,CAAC;AACpB,QAAA,kBAAkB,EAAEC,mBAAY,CAAC,IAAI,CAAC;AACpC,YAAA,OAAO,EAAE;gBACP,OAAO,EAAE,OAAO,CAAC,OAAO;AACzB,aAAA;SACF,CAAC;QACF,YAAY;AACb,KAAA,CAAC;AACJ;;;;"}
|
|
@@ -2,9 +2,8 @@ import { NextRequest, NextResponse } from 'next/server';
|
|
|
2
2
|
import { Auth0Client } from '@auth0/nextjs-auth0/server';
|
|
3
3
|
import { Brand } from 'src/types/brand';
|
|
4
4
|
import { Auth0Config } from 'src/types';
|
|
5
|
-
export declare const handleUserProfile: ({ request,
|
|
5
|
+
export declare const handleUserProfile: ({ request, auth0Instance, auth0Config, brand, }: {
|
|
6
6
|
request: NextRequest;
|
|
7
|
-
response: NextResponse;
|
|
8
7
|
auth0Instance: Auth0Client;
|
|
9
8
|
auth0Config: Auth0Config;
|
|
10
9
|
brand: Brand;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var server = require('next/server');
|
|
4
4
|
var session = require('../../lib/enrichUser/session.js');
|
|
5
|
-
var proactivelyRefreshAccessToken = require('./proactivelyRefreshAccessToken.js');
|
|
6
5
|
var addCachingHeaders = require('./addCachingHeaders.js');
|
|
7
6
|
|
|
8
7
|
const noUserResponse = new server.NextResponse(null, {
|
|
@@ -14,25 +13,35 @@ const noUserResponse = new server.NextResponse(null, {
|
|
|
14
13
|
Expires: '0',
|
|
15
14
|
},
|
|
16
15
|
});
|
|
17
|
-
const handleUserProfile = async ({ request,
|
|
16
|
+
const handleUserProfile = async ({ request, auth0Instance, auth0Config, brand, }) => {
|
|
17
|
+
// eslint-disable-next-line no-console
|
|
18
|
+
console.debug({
|
|
19
|
+
message: 'handleUserProfile: start',
|
|
20
|
+
pathname: request.nextUrl.pathname,
|
|
21
|
+
profileEndpoint: auth0Config.userProfileEndpoint,
|
|
22
|
+
});
|
|
18
23
|
try {
|
|
19
24
|
if (request.nextUrl.pathname === auth0Config.userProfileEndpoint) {
|
|
20
25
|
const session$1 = await auth0Instance.getSession(request);
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
27
|
+
console.debug({
|
|
28
|
+
message: 'handleUserProfile: session',
|
|
29
|
+
session: session$1,
|
|
30
|
+
});
|
|
21
31
|
if (!session$1) {
|
|
22
32
|
return noUserResponse;
|
|
23
33
|
}
|
|
24
|
-
const { token } = await proactivelyRefreshAccessToken.proactivelyRefreshAccessToken({
|
|
25
|
-
request,
|
|
26
|
-
response,
|
|
27
|
-
auth0Instance,
|
|
28
|
-
auth0Config,
|
|
29
|
-
});
|
|
30
34
|
const user = session$1.user;
|
|
31
35
|
const enrichedUser = await session.enrichUser({
|
|
32
36
|
user,
|
|
33
|
-
accessToken:
|
|
37
|
+
accessToken: session$1.tokenSet.accessToken,
|
|
34
38
|
brand,
|
|
35
39
|
});
|
|
40
|
+
// eslint-disable-next-line no-console
|
|
41
|
+
console.debug({
|
|
42
|
+
message: 'handleUserProfile: enrichedUser',
|
|
43
|
+
enrichedUser,
|
|
44
|
+
});
|
|
36
45
|
const userResponse = server.NextResponse.json(enrichedUser);
|
|
37
46
|
addCachingHeaders.addCachingHeaders(userResponse);
|
|
38
47
|
return userResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.js","sources":["../../../../../src/server/middleware/profile.ts"],"sourcesContent":[null],"names":["NextResponse","session","
|
|
1
|
+
{"version":3,"file":"profile.js","sources":["../../../../../src/server/middleware/profile.ts"],"sourcesContent":[null],"names":["NextResponse","session","enrichUser","addCachingHeaders"],"mappings":";;;;;;AASA,MAAM,cAAc,GAAG,IAAIA,mBAAY,CAAC,IAAI,EAAE;AAC5C,IAAA,MAAM,EAAE,GAAG;AACX,IAAA,OAAO,EAAE;AACP,QAAA,IAAI,EAAE,uBAAuB;AAC7B,QAAA,eAAe,EAAE,yDAAyD;AAC1E,QAAA,MAAM,EAAE,UAAU;AAClB,QAAA,OAAO,EAAE,GAAG;AACb,KAAA;AACF,CAAA,CAAC;AAEK,MAAM,iBAAiB,GAAG,OAAO,EACtC,OAAO,EACP,aAAa,EACb,WAAW,EACX,KAAK,GAMN,KAAkC;;IAEjC,OAAO,CAAC,KAAK,CAAC;AACZ,QAAA,OAAO,EAAE,0BAA0B;AACnC,QAAA,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ;QAClC,eAAe,EAAE,WAAW,CAAC,mBAAmB;AACjD,KAAA,CAAC;AAEF,IAAA,IAAI;QACF,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,KAAK,WAAW,CAAC,mBAAmB,EAAE;YAChE,MAAMC,SAAO,GAAG,MAAM,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC;;YAGvD,OAAO,CAAC,KAAK,CAAC;AACZ,gBAAA,OAAO,EAAE,4BAA4B;yBACrCA,SAAO;AACR,aAAA,CAAC;YAEF,IAAI,CAACA,SAAO,EAAE;AACZ,gBAAA,OAAO,cAAc;YACvB;AAEA,YAAA,MAAM,IAAI,GAAGA,SAAO,CAAC,IAAmB;AAExC,YAAA,MAAM,YAAY,GAAG,MAAMC,kBAAU,CAAC;gBACpC,IAAI;AACJ,gBAAA,WAAW,EAAED,SAAO,CAAC,QAAQ,CAAC,WAAW;gBACzC,KAAK;AACN,aAAA,CAAC;;YAGF,OAAO,CAAC,KAAK,CAAC;AACZ,gBAAA,OAAO,EAAE,iCAAiC;gBAC1C,YAAY;AACb,aAAA,CAAC;YAEF,MAAM,YAAY,GAAGD,mBAAY,CAAC,IAAI,CAAC,YAAY,CAAC;YACpDG,mCAAiB,CAAC,YAAY,CAAC;AAC/B,YAAA,OAAO,YAAY;QACrB;IACF;IAAE,OAAO,KAAK,EAAE;;QAEd,OAAO,CAAC,KAAK,CAAC;AACZ,YAAA,IAAI,EAAE,oDAAoD;YAC1D,KAAK;AACN,SAAA,CAAC;AACF,QAAA,OAAO,cAAc;IACvB;AACF;;;;"}
|
|
@@ -20,6 +20,13 @@ const isAuthRoute = (pathname, auth0Config) => {
|
|
|
20
20
|
};
|
|
21
21
|
const authMiddleware = async ({ request, isProtectedRoute, language, host, protocol, onError, brand, }) => {
|
|
22
22
|
const { pathname } = request.nextUrl;
|
|
23
|
+
// eslint-disable-next-line no-console
|
|
24
|
+
console.debug({
|
|
25
|
+
message: 'authMiddleware: start',
|
|
26
|
+
pathname,
|
|
27
|
+
host,
|
|
28
|
+
protocol,
|
|
29
|
+
});
|
|
23
30
|
const auth0Instance = getAuth0Instance({
|
|
24
31
|
host,
|
|
25
32
|
protocol,
|
|
@@ -32,6 +39,11 @@ const authMiddleware = async ({ request, isProtectedRoute, language, host, proto
|
|
|
32
39
|
request,
|
|
33
40
|
auth0Config,
|
|
34
41
|
});
|
|
42
|
+
// eslint-disable-next-line no-console
|
|
43
|
+
console.debug({
|
|
44
|
+
message: 'authMiddleware: crossDomainLogoutResult',
|
|
45
|
+
crossDomainLogoutResult: !!crossDomainLogoutResult,
|
|
46
|
+
});
|
|
35
47
|
if (crossDomainLogoutResult) {
|
|
36
48
|
return crossDomainLogoutResult;
|
|
37
49
|
}
|
|
@@ -53,16 +65,25 @@ const authMiddleware = async ({ request, isProtectedRoute, language, host, proto
|
|
|
53
65
|
auth0Config,
|
|
54
66
|
onError,
|
|
55
67
|
});
|
|
68
|
+
// eslint-disable-next-line no-console
|
|
69
|
+
console.debug({
|
|
70
|
+
message: 'authMiddleware: accessTokenRequestResult',
|
|
71
|
+
accessTokenRequestResult: !!accessTokenRequestResult,
|
|
72
|
+
});
|
|
56
73
|
if (accessTokenRequestResult) {
|
|
57
74
|
return accessTokenRequestResult;
|
|
58
75
|
}
|
|
59
76
|
const handleUserProfileResult = await handleUserProfile({
|
|
60
77
|
request,
|
|
61
|
-
response: authResponse,
|
|
62
78
|
auth0Instance,
|
|
63
79
|
auth0Config,
|
|
64
80
|
brand,
|
|
65
81
|
});
|
|
82
|
+
// eslint-disable-next-line no-console
|
|
83
|
+
console.debug({
|
|
84
|
+
message: 'authMiddleware: handleUserProfileResult',
|
|
85
|
+
handleUserProfileResult: !!handleUserProfileResult,
|
|
86
|
+
});
|
|
66
87
|
if (handleUserProfileResult) {
|
|
67
88
|
return handleUserProfileResult;
|
|
68
89
|
}
|
|
@@ -79,6 +100,11 @@ const authMiddleware = async ({ request, isProtectedRoute, language, host, proto
|
|
|
79
100
|
response: authResponse,
|
|
80
101
|
onError,
|
|
81
102
|
});
|
|
103
|
+
// eslint-disable-next-line no-console
|
|
104
|
+
console.debug({
|
|
105
|
+
message: 'authMiddleware: protectRouteResult',
|
|
106
|
+
protectRouteResult: !!protectRouteResult,
|
|
107
|
+
});
|
|
82
108
|
if (protectRouteResult) {
|
|
83
109
|
return protectRouteResult;
|
|
84
110
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../src/server/middleware/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;AAeA,MAAM,WAAW,GAAG,CAAC,QAAgB,EAAE,WAAwB,KAAI;AACjE,IAAA,MAAM,EACJ,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,GACd,GAAG,WAAW;IAEf,OAAO;QACL,aAAa;QACb,cAAc;QACd,gBAAgB;QAChB,mBAAmB;QACnB,aAAa;AACd,KAAA,CAAC,QAAQ,CAAC,QAAQ,CAAC;AACtB,CAAC;MAEY,cAAc,GAAG,OAAO,EACnC,OAAO,EACP,gBAAgB,EAChB,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,KAAK,GASN,KAA2B;AAC1B,IAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,OAAO;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/server/middleware/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;AAeA,MAAM,WAAW,GAAG,CAAC,QAAgB,EAAE,WAAwB,KAAI;AACjE,IAAA,MAAM,EACJ,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,GACd,GAAG,WAAW;IAEf,OAAO;QACL,aAAa;QACb,cAAc;QACd,gBAAgB;QAChB,mBAAmB;QACnB,aAAa;AACd,KAAA,CAAC,QAAQ,CAAC,QAAQ,CAAC;AACtB,CAAC;MAEY,cAAc,GAAG,OAAO,EACnC,OAAO,EACP,gBAAgB,EAChB,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,KAAK,GASN,KAA2B;AAC1B,IAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,OAAO;;IAGpC,OAAO,CAAC,KAAK,CAAC;AACZ,QAAA,OAAO,EAAE,uBAAuB;QAChC,QAAQ;QACR,IAAI;QACJ,QAAQ;AACT,KAAA,CAAC;IAEF,MAAM,aAAa,GAAG,gBAAgB,CAAC;QACrC,IAAI;QACJ,QAAQ;AACT,KAAA,CAAC;AAEF,IAAA,MAAM,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,QAAA,OAAO,uBAAuB;IAChC;IAEA,IAAI,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC,IAAI,gBAAgB,EAAE;AAC1D,QAAA,OAAO,YAAY;IACrB;IAEA,MAAM,WAAW,GAAG,CAAC,gBAAgB,IAAI,gBAAgB,CAAC,QAAQ,CAAC;AACnE,IAAA,MAAM,kBAAkB,GAAG,MAAM,YAAY,CAAC;QAC5C,WAAW;QACX,aAAa;QACb,WAAW;QACX,QAAQ;QACR,OAAO;AACP,QAAA,QAAQ,EAAE,YAAY;QACtB,OAAO;AACR,KAAA,CAAC;;IAEF,OAAO,CAAC,KAAK,CAAC;AACZ,QAAA,OAAO,EAAE,oCAAoC;QAC7C,kBAAkB,EAAE,CAAC,CAAC,kBAAkB;AACzC,KAAA,CAAC;IACF,IAAI,kBAAkB,EAAE;AACtB,QAAA,OAAO,kBAAkB;IAC3B;AAEA,IAAA,OAAO,cAAc,CAAC;AACpB,QAAA,kBAAkB,EAAE,YAAY,CAAC,IAAI,CAAC;AACpC,YAAA,OAAO,EAAE;gBACP,OAAO,EAAE,OAAO,CAAC,OAAO;AACzB,aAAA;SACF,CAAC;QACF,YAAY;AACb,KAAA,CAAC;AACJ;;;;"}
|
|
@@ -2,9 +2,8 @@ import { NextRequest, NextResponse } from 'next/server';
|
|
|
2
2
|
import { Auth0Client } from '@auth0/nextjs-auth0/server';
|
|
3
3
|
import { Brand } from 'src/types/brand';
|
|
4
4
|
import { Auth0Config } from 'src/types';
|
|
5
|
-
export declare const handleUserProfile: ({ request,
|
|
5
|
+
export declare const handleUserProfile: ({ request, auth0Instance, auth0Config, brand, }: {
|
|
6
6
|
request: NextRequest;
|
|
7
|
-
response: NextResponse;
|
|
8
7
|
auth0Instance: Auth0Client;
|
|
9
8
|
auth0Config: Auth0Config;
|
|
10
9
|
brand: Brand;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server';
|
|
2
2
|
import { enrichUser } from '../../lib/enrichUser/session.js';
|
|
3
|
-
import { proactivelyRefreshAccessToken } from './proactivelyRefreshAccessToken.js';
|
|
4
3
|
import { addCachingHeaders } from './addCachingHeaders.js';
|
|
5
4
|
|
|
6
5
|
const noUserResponse = new NextResponse(null, {
|
|
@@ -12,25 +11,35 @@ const noUserResponse = new NextResponse(null, {
|
|
|
12
11
|
Expires: '0',
|
|
13
12
|
},
|
|
14
13
|
});
|
|
15
|
-
const handleUserProfile = async ({ request,
|
|
14
|
+
const handleUserProfile = async ({ request, auth0Instance, auth0Config, brand, }) => {
|
|
15
|
+
// eslint-disable-next-line no-console
|
|
16
|
+
console.debug({
|
|
17
|
+
message: 'handleUserProfile: start',
|
|
18
|
+
pathname: request.nextUrl.pathname,
|
|
19
|
+
profileEndpoint: auth0Config.userProfileEndpoint,
|
|
20
|
+
});
|
|
16
21
|
try {
|
|
17
22
|
if (request.nextUrl.pathname === auth0Config.userProfileEndpoint) {
|
|
18
23
|
const session = await auth0Instance.getSession(request);
|
|
24
|
+
// eslint-disable-next-line no-console
|
|
25
|
+
console.debug({
|
|
26
|
+
message: 'handleUserProfile: session',
|
|
27
|
+
session,
|
|
28
|
+
});
|
|
19
29
|
if (!session) {
|
|
20
30
|
return noUserResponse;
|
|
21
31
|
}
|
|
22
|
-
const { token } = await proactivelyRefreshAccessToken({
|
|
23
|
-
request,
|
|
24
|
-
response,
|
|
25
|
-
auth0Instance,
|
|
26
|
-
auth0Config,
|
|
27
|
-
});
|
|
28
32
|
const user = session.user;
|
|
29
33
|
const enrichedUser = await enrichUser({
|
|
30
34
|
user,
|
|
31
|
-
accessToken:
|
|
35
|
+
accessToken: session.tokenSet.accessToken,
|
|
32
36
|
brand,
|
|
33
37
|
});
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
39
|
+
console.debug({
|
|
40
|
+
message: 'handleUserProfile: enrichedUser',
|
|
41
|
+
enrichedUser,
|
|
42
|
+
});
|
|
34
43
|
const userResponse = NextResponse.json(enrichedUser);
|
|
35
44
|
addCachingHeaders(userResponse);
|
|
36
45
|
return userResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.js","sources":["../../../../../src/server/middleware/profile.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"profile.js","sources":["../../../../../src/server/middleware/profile.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AASA,MAAM,cAAc,GAAG,IAAI,YAAY,CAAC,IAAI,EAAE;AAC5C,IAAA,MAAM,EAAE,GAAG;AACX,IAAA,OAAO,EAAE;AACP,QAAA,IAAI,EAAE,uBAAuB;AAC7B,QAAA,eAAe,EAAE,yDAAyD;AAC1E,QAAA,MAAM,EAAE,UAAU;AAClB,QAAA,OAAO,EAAE,GAAG;AACb,KAAA;AACF,CAAA,CAAC;AAEK,MAAM,iBAAiB,GAAG,OAAO,EACtC,OAAO,EACP,aAAa,EACb,WAAW,EACX,KAAK,GAMN,KAAkC;;IAEjC,OAAO,CAAC,KAAK,CAAC;AACZ,QAAA,OAAO,EAAE,0BAA0B;AACnC,QAAA,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ;QAClC,eAAe,EAAE,WAAW,CAAC,mBAAmB;AACjD,KAAA,CAAC;AAEF,IAAA,IAAI;QACF,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,KAAK,WAAW,CAAC,mBAAmB,EAAE;YAChE,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC;;YAGvD,OAAO,CAAC,KAAK,CAAC;AACZ,gBAAA,OAAO,EAAE,4BAA4B;gBACrC,OAAO;AACR,aAAA,CAAC;YAEF,IAAI,CAAC,OAAO,EAAE;AACZ,gBAAA,OAAO,cAAc;YACvB;AAEA,YAAA,MAAM,IAAI,GAAG,OAAO,CAAC,IAAmB;AAExC,YAAA,MAAM,YAAY,GAAG,MAAM,UAAU,CAAC;gBACpC,IAAI;AACJ,gBAAA,WAAW,EAAE,OAAO,CAAC,QAAQ,CA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