You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when you run function of the auth in the middleware , you may get the error like this below,
⨯ ./node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:76:15
Module not found: Can't resolve 'aws-sdk' 74 | 75 | // if not mocking then setup real s3.> 76 | const AWS = require('aws-sdk'); | ^^^^^^^^^^^^^^^^^^ 77 | 78 | AWS.config.update(config); 79 | const s3 = new AWS.S3();https://nextjs.org/docs/messages/module-not-found ⨯ ./node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:76:15Module not found: Can't resolve 'aws-sdk'
74 |
75 | // if not mocking then setup real s3.
> 76 | const AWS = require('aws-sdk');| ^^^^^^^^^^^^^^^^^^
77 |
78 | AWS.config.update(config);
79 | const s3 = new AWS.S3();
https://nextjs.org/docs/messages/module-not-found
⨯ ./node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:43:21
Module not found: Can't resolve 'mock-aws-s3' 41 | // here we're mocking. node_pre_gyp_mock_s3 is the scratch directory
42 | // for the mock code.
> 43 | const AWSMock = require('mock-aws-s3');| ^^^^^^^^^^^^^^^^^^^^^^
44 | const os = require('os');
45 |
46 | AWSMock.config.basePath = `${os.tmpdir()}/mock`;https://nextjs.org/docs/messages/module-not-found ⨯ ./node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:43:21Module not found: Can't resolve 'mock-aws-s3' 41 | // here we're mocking. node_pre_gyp_mock_s3 is the scratch directory 42 | // for the mock code.> 43 | const AWSMock = require('mock-aws-s3');| ^^^^^^^^^^^^^^^^^^^^^^ 44 | const os = require('os'); 45 | 46 | AWSMock.config.basePath = `${os.tmpdir()}/mock`;https://nextjs.org/docs/messages/module-not-found ⨯ ./node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:112:16Module not found: Can't resolve 'nock' 110 | } 111 |> 112 | const nock = require('nock'); | ^^^^^^^^^^^^^^^ 113 | // the bucket used for testing, as addressed by https. 114 | const host = 'https://mapbox-node-pre-gyp-public-testing-bucket.s3.us-east-1.amazonaws.com'; 115 | const mockDir = process.env.node_pre_gyp_mock_s3 + '/mapbox-node-pre-gyp-public-testing-bucket';https://nextjs.org/docs/messages/module-not-found ⨯ ./node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:112:16Module not found: Can't resolve 'nock' 110 | } 111 |> 112 | const nock = require('nock');| ^^^^^^^^^^^^^^^ 113 | // the bucket used for testing, as addressed by https. 114 | const host = 'https://mapbox-node-pre-gyp-public-testing-bucket.s3.us-east-1.amazonaws.com'; 115 | const mockDir = process.env.node_pre_gyp_mock_s3 + '/mapbox-node-pre-gyp-public-testing-bucket';
so that we can't use the auth function in the middleware.tsx to check the login status, that wasn't caused by the auth function but caused by the enscryption modle, so instead of use the auth function, there were here I have tried and use a new solution to get what you want, easy and fast, also worked when deploy the projects in the Vercel.
Non-Goals
Background
to make check the user login status easy and modifiable in the middleware, we can do like this , just use the codes here below, I tried , which works on the Vercel and self-host server's projects
// middlware.tsximport{decode}from'next-auth/jwt'// decrypt the token content import{cookies}from'next/headers'// get you login coockies// get the logined and authed coockiesconstGetJWTToken=()=>{constcookie=cookies();constcookieKeysList=['authjs.session-token','__Secure-authjs.session-token']for(letkeyofcookieKeysList){constloginCookies=cookie.get(key);if(loginCookies&&loginCookies.name==key&&loginCookies.value.toString().trim().length>0){return{token:loginCookies.value.toString().trim(),salt:key}}}returnnull}// decode the cookies and get the datas you wantexportasyncfunctionmiddleware(request: NextRequest){
.........
constJWTCookieToken=GetJWTToken()constsecret=proccess.env.AUTH_SECRET// this secret is the auth secret when you used to enscrypt in the `NextAuth`if(JWTCookieToken&&secret){// decode the data you want in the login coockies and then you can get the token you wantconsttoken_decoded=awaitdecode({secret, ...JWTCookieToken})console.info(`you login decode inform is `,token_decoded)}
.........
}
through the ways above you can get the token details in the middleware just like the functions of the auth , and also if you use the encrypt funtions of you own and decrypt function defined by youself, you just replace the decode functions with your own decrypt functions
Proposal
to make check the user login status easily in the middleware,
if needed and I can help optimise the code of the source and do some of the contribute
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Goals
when you run function of the
auth
in the middleware , you may get the error like this below,so that we can't use the
auth
function in themiddleware.tsx
to check the login status, that wasn't caused by the auth function but caused by the enscryption modle, so instead of use theauth
function, there were here I have tried and use a new solution to get what you want, easy and fast, also worked when deploy the projects in the Vercel.Non-Goals
Background
to make check the user login status easy and modifiable in the middleware, we can do like this , just use the codes here below, I tried , which works on the Vercel and self-host server's projects
through the ways above you can get the token details in the middleware just like the functions of the auth , and also if you use the encrypt funtions of you own and decrypt function defined by youself, you just replace the
decode
functions with your own decrypt functionsProposal
to make check the user login status easily in the middleware,
if needed and I can help optimise the code of the source and do some of the contribute
Beta Was this translation helpful? Give feedback.
All reactions