khanprog
12/22/2023, 11:22 AM{t: "2023-12-22T11:15:13.063Z", message: "middleware: Started", file: "/gateway/node_modules/supertokens-node/lib/build/supertokens.js:145:22" sdkVer: "16.6.5"}
2023-12-22T11:15:13.072Z com.supertokens {t: "2023-12-22T11:15:13.072Z", message: "middleware: Not handling because request path did not start with config path. Request path: /.well-known/jwks.json", file: "/gateway/node_modules/supertokens-node/lib/build/supertokens.js:152:26" sdkVer: "16.6.5"}
rp_st
12/22/2023, 11:25 AMkhanprog
12/22/2023, 11:25 AMrp_st
12/22/2023, 11:26 AMkhanprog
12/22/2023, 11:26 AMsupertokens.init({
debug: true,
framework: 'express',
supertokens: {
connectionURI: 'http://supertokens:3567'
// apiKey: "", // TODO: Set an API key later on
},
appInfo: {
appName: 'APP',
apiDomain: 'http://localhost:3001',
websiteDomain: 'http://localhost:3001',
apiBasePath: '/auth',
websiteBasePath: '/auth'
},
recipeList: [
EmailPassword.init({
signUpFeature: {
formFields: [ // TODO: Update this to match the signup form
{
id: 'email'
},
{
id: 'password'
}
]
}
}),
Session.init({
cookieSecure: true
}), // TODO: Update this section for proper handling
Dashboard.init(), // TODO: see if we can add more things to the dashboard
UserRoles.init()
]
})
rp_st
12/22/2023, 11:26 AM/auth
. In nextjs, it should be /api/auth
khanprog
12/22/2023, 11:27 AMrp_st
12/22/2023, 11:27 AMkhanprog
12/22/2023, 11:27 AMkhanprog
12/22/2023, 11:28 AMimport Session from 'supertokens-node/recipe/session';
rp_st
12/22/2023, 11:28 AMkhanprog
12/22/2023, 11:29 AMrp_st
12/22/2023, 11:29 AMkhanprog
12/22/2023, 11:30 AMrp_st
12/22/2023, 11:31 AM/api/auth
khanprog
12/22/2023, 11:33 AM/api
folder of nextjs. what if I want to use graphql for handling things, the thing is its working for signin and singup but not for this specific case where I put it in the middlewareporcellus
12/22/2023, 11:33 AMkhanprog
12/22/2023, 11:33 AMporcellus
12/22/2023, 11:38 AM/auth/.well-known/jwks.json
on your backend?khanprog
12/22/2023, 11:40 AMCannot GET /auth/.well-known/jwks.json
khanprog
12/22/2023, 11:40 AMporcellus
12/22/2023, 11:41 AMrp_st
12/22/2023, 11:41 AMrp_st
12/22/2023, 11:41 AM/.well-known/jwks.json
khanprog
12/22/2023, 11:41 AMrp_st
12/22/2023, 11:41 AMkhanprog
12/22/2023, 11:41 AMporcellus
12/22/2023, 11:42 AMrp_st
12/22/2023, 11:42 AMkhanprog
12/22/2023, 11:42 AMAppId or tenantId not found => Tenant with the following connectionURIDomain, appId and tenantId combination not found: (, public, auth)
rp_st
12/22/2023, 11:42 AM/auth/jwt/jwks.json
rp_st
12/22/2023, 11:43 AM/auth
part..rp_st
12/22/2023, 11:43 AM<core domain>/.well-known/jwks.json
porcellus
12/22/2023, 11:44 AMkhanprog
12/22/2023, 11:44 AM{
"keys": [
{
"kty": "RSA",
"kid": "d-1703142523611",
"n": "ueyhzEB2kHdMixxi0V7rTkO64W08avpkSgZj7ltAkRrxYuV5gLBWDYcbUga3s1Ble76kLXS6xyjHUU0g8FvRC_g0AYrjllG-XoMU1CMCY8zrlULxM3S7yOmifUzZN3GmeCksnm7kNppj9MWFSAwC29VmekFJC0aPDp1pc4TNx3VKqvayrdF2pzlqqITQGJGQHquNC3vsky10ozXO0B168Fc76XYtDzF0aGFRMhuwwbEF5px-trdWryxHwUKi7tYD8OH-A-xVvKNBGjwXN_Uyote1ndD8AXLlES3oi-5_DBcrQZMJdXzCsxIE0njjxlBacldif2U8oTr3e8XrFGuXaw",
"e": "AQAB",
"alg": "RS256",
"use": "sig"
},
{
"kty": "RSA",
"kid": "s-3e2e2f9a-e5c8-4498-9ab7-2bf8a5e8304e",
"n": "pO40XRroIc7slSgoE3lxEJIxUiIt9WFdeKjd9oBEfuZIe24Jev_xCdhLWzV9Aa8eH4HLa1pqxwM7o4El4LHpzczZcrpyxVTN-CyZTE4axcxGp_Nxi41PvrPsUlQoJQ0OFxRpQRecauUr4v57agphF2GSzIREhZot6ldx5WSSJOqKYmWuoDCh7dredpgiLREnvUeXl58AdFlyjWswr_JC4l_RbWFwPfdto4-xGxjZd9SLioB83n4vyv7VLaX1j2Pns6OiB0Zt7sAW8E0bVlW2Yy34zt7Mu-aswWv2c0BB_VbMkbQIv-gh65qwDfkNIw91XQv_PAf6Olxy0R8YsaqW3w",
"e": "AQAB",
"alg": "RS256",
"use": "sig"
}
]
}
porcellus
12/22/2023, 11:45 AMporcellus
12/22/2023, 11:45 AMporcellus
12/22/2023, 11:46 AMkhanprog
12/22/2023, 11:46 AMrp_st
12/22/2023, 11:46 AMrp_st
12/22/2023, 11:46 AMkhanprog
12/22/2023, 11:46 AMkhanprog
12/22/2023, 11:48 AMimport { NextResponse } from 'next/server';
import { withSession } from 'utils/sessionUtils';
export function middleware(request) {
if (
request.nextUrl.pathname.startsWith('/admin/login') ||
request.nextUrl.pathname.startsWith('/app/login')
) {
return NextResponse.next();
}
if (request.headers.has('x-user-id')) {
console.warn(
'The FE tried to pass x-user-id, which is only supposed to be a backend internal header. Ignoring.',
);
request.headers.delete('x-user-id');
}
if (request.nextUrl.pathname.startsWith('/api/user')) {
return NextResponse.next();
}
return withSession(request, async (session) => {
console.log(
'🚀 ~ file: middleware.js:16 ~ returnwithSession ~ session:',
session,
);
if (session === undefined) {
return NextResponse.redirect(new URL('/admin/login', request.url));
}
return NextResponse.next({
headers: {
'x-user-id': session.getUserId(),
},
});
});
}
export const config = {
matcher: ['/admin/:path*', '/app/:path*'],
};
rp_st
12/22/2023, 11:48 AMrp_st
12/22/2023, 11:48 AMrp_st
12/22/2023, 11:49 AMhttp://supertokens:3567
in your connection uri point to the core or to the next backend?khanprog
12/22/2023, 11:49 AMrp_st
12/22/2023, 11:49 AMkhanprog
12/22/2023, 11:49 AMkhanprog
12/22/2023, 11:50 AMexport async function getSSRSession(req, options = {}) {
const query =
req !== undefined
? Object.fromEntries(new URL(req.url).searchParams.entries())
: {};
const parsedCookies = Object.fromEntries(
(req !== undefined ? req.cookies : cookies())
.getAll()
.map((cookie) => [cookie.name, cookie.value]),
);
let baseRequest = new PreParsedRequest({
method: req !== undefined ? req.method : 'get',
url: req !== undefined ? req.url : '',
query: query,
headers: req !== undefined ? req.headers : headers(),
cookies: parsedCookies,
getFormBody: () => req.formData(),
getJSONBody: () => req.json(),
});
let baseResponse = new CollectingResponse();
try {
let session = await Session.getSession(baseRequest, baseResponse, options);
return {
session,
hasInvalidClaims: false,
hasToken: session !== undefined,
baseResponse,
};
} catch (err) {
console.log('🚀 ~ file: sessionUtils.js:47 ~ err:', err.message);
if (Session.Error.isErrorFromSuperTokens(err)) {
return {
hasToken: err.type !== Session.Error.UNAUTHORISED,
hasInvalidClaims: err.type === Session.Error.INVALID_CLAIMS,
session: undefined,
baseResponse,
nextResponse: new NextResponse('Authentication required', {
status: err.type === Session.Error.INVALID_CLAIMS ? 403 : 401,
}),
};
} else {
throw err;
}
}
}
khanprog
12/22/2023, 11:51 AMrp_st
12/22/2023, 11:51 AMrp_st
12/22/2023, 11:51 AMkhanprog
12/22/2023, 11:52 AMimport EmailPassword from 'supertokens-node/recipe/emailpassword'
import Session from 'supertokens-node/recipe/session'
import { appInfo } from './appInfo'
import SuperTokens from 'supertokens-node'
export const backendConfig = () => {
return {
framework: "express",
supertokens: {
connectionURI: "http://localhost:3001",
},
appInfo,
recipeList: [
EmailPassword.init(),
Session.init(),
],
isInServerlessEnv: false,
}
}
let initialized = false
export function ensureSuperTokensInit() {
if (!initialized) {
SuperTokens.init(backendConfig())
initialized = true
}
}
rp_st
12/22/2023, 11:52 AMrp_st
12/22/2023, 11:52 AMrp_st
12/22/2023, 11:53 AMkhanprog
12/22/2023, 11:53 AMkhanprog
12/22/2023, 12:00 PMrp_st
12/22/2023, 12:01 PM