idanh.
08/28/2022, 6:19 PMGqlExecutionContext.create(context)
and also tried injecting the session param to the resolver with
export const User = createParamDecorator(
(data: unknown, ctx: ExecutionContext) => {
const x = GqlExecutionContext.create(ctx);
const context = x.getContext();
return context.session;
},
);
with no success
and couldn't find any code example that combines graphql + nestrp_st
08/28/2022, 6:20 PMrp_st
08/28/2022, 6:20 PMrp_st
08/28/2022, 6:21 PMporcellus
08/28/2022, 6:33 PMporcellus
08/28/2022, 6:34 PMidanh.
08/28/2022, 7:14 PMconsole.log('requestForST.session: ', requestForST.session);
on the pluginidanh.
08/28/2022, 7:25 PMporcellus
08/28/2022, 10:09 PMporcellus
08/28/2022, 10:11 PMidanh.
08/29/2022, 4:45 AMmessage: "middleware: requestRID is: anti-csrf"
"middleware: Checking recipe ID for match: thirdpartyemailpassword"
"middleware: Checking recipe ID for match: session"
"middleware: Not handling because no recipe matched"
the first log led me here https://github.com/supertokens/supertokens-node/issues/202
so i tried manually setting the rid header to thirdpartyemailpassword
2. now i'm getting "middleware: Not handling because request path did not start with config path. Request path: /graphql"
where my appInfo config has apiBasePath: '/api/auth'
and my request goes to /graphql
so I changed my server path to /api/auth/graphql
3. i'm getting a match
"middleware: requestRID is: thirdpartyemailpassword"
"middleware: Matched with recipe ID: thirdpartyemailpassword"
"middleware: Not handling because recipe doesn't handle request path or method. Request path: /api/auth/graphql, request method: post"
not sure how to move forwardporcellus
08/29/2022, 6:28 AMporcellus
08/29/2022, 6:30 AMverifySession
. I'd start by putting logs (kind of like separators) before and after the verifySession
call and checking what happens there.idanh.
08/29/2022, 7:14 AM/graphql
while my apiBasePath is /api/auth
I log in with google successfully, but I don't manage to get the session info neither on the first login cycle nor when i refresh the client - here's the full log for clarity:idanh.
08/29/2022, 7:15 AMidanh.
08/29/2022, 7:16 AMcom.supertokens {t: "2022-08-29T07:11:20.481Z", message: "middleware: Started", file: "/Users/idanhaviv/Developer/yooz-server/node_modules/supertokens-node/lib/build/supertokens.js:224:26" sdkVer: "11.2.0"} +0ms
com.supertokens {t: "2022-08-29T07:11:20.481Z", message: "middleware: Not handling because request path did not start with config path. Request path: /graphql", file: "/Users/idanhaviv/Developer/yooz-server/node_modules/supertokens-node/lib/build/supertokens.js:231:30" sdkVer: "11.2.0"} +0ms
com.supertokens {t: "2022-08-29T07:11:20.483Z", message: "getSession: Started", file: "/Users/idanhaviv/Developer/yooz-server/node_modules/supertokens-node/lib/build/recipe/session/recipeImplementation.js:135:26" sdkVer: "11.2.0"} +0ms
com.supertokens {t: "2022-08-29T07:11:20.483Z", message: "getSession: rid in header: true", file: "/Users/idanhaviv/Developer/yooz-server/node_modules/supertokens-node/lib/build/recipe/session/recipeImplementation.js:136:26" sdkVer: "11.2.0"} +0ms
com.supertokens {t: "2022-08-29T07:11:20.483Z", message: "getSession: request method: post", file: "/Users/idanhaviv/Developer/yooz-server/node_modules/supertokens-node/lib/build/recipe/session/recipeImplementation.js:137:26" sdkVer: "11.2.0"} +0ms
com.supertokens {t: "2022-08-29T07:11:20.484Z", message: "getSession: returning undefined because idRefreshToken is undefined and sessionRequired is false", file: "/Users/idanhaviv/Developer/yooz-server/node_modules/supertokens-node/lib/build/recipe/session/recipeImplementation.js:144:34" sdkVer: "11.2.0"} +0ms
idanh.
08/29/2022, 7:23 AMcom.supertokens {t: "2022-08-29T07:20:16.760Z", message: "getSession: UNAUTHORISED because idRefreshToken from cookies is undefined", file: "/Users/idanhaviv/Developer/yooz-server/node_modules/supertokens-node/lib/build/recipe/session/recipeImplementation.js:151:30" sdkVer: "11.2.0"} +0ms
com.supertokens {t: "2022-08-29T07:20:16.760Z", message: "errorHandler: Started", file: "/Users/idanhaviv/Developer/yooz-server/node_modules/supertokens-node/lib/build/supertokens.js:315:26" sdkVer: "11.2.0"} +0ms
com.supertokens {t: "2022-08-29T07:20:16.760Z", message: "errorHandler: Error is from SuperTokens recipe. Message: Session does not exist. Are you sending the session tokens in the request as cookies?", file: "/Users/idanhaviv/Developer/yooz-server/node_modules/supertokens-node/lib/build/supertokens.js:317:30" sdkVer: "11.2.0"} +0ms
idanh.
08/29/2022, 7:48 AMporcellus
08/29/2022, 8:10 AMporcellus
08/29/2022, 8:11 AMporcellus
08/29/2022, 8:11 AMporcellus
08/29/2022, 8:14 AMidanh.
08/29/2022, 8:31 AMsIRTFrontend
sFrontToken
sAccessToken
ajs_user_id
sIdRefreshToken
ajs_anonymous_id
idanh.
08/29/2022, 8:32 AMidanh.
08/29/2022, 8:32 AMporcellus
08/29/2022, 8:40 AMrequestForST
idanh.
08/29/2022, 8:45 AMaccept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Content-Length: 342
content-type: application/json
Host: localhost:4000
Origin: http://localhost:3000
Referer: http://localhost:3000/
rid: anti-csrf
sec-ch-ua: "Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
requestForST:
requestForST: {
headers: {
accept: '*/*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.9',
connection: 'keep-alive',
'content-length': '342',
'content-type': 'application/json',
host: 'localhost:4000',
origin: 'http://localhost:3000',
referer: 'http://localhost:3000/',
rid: 'anti-csrf',
'sec-ch-ua': '"Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"macOS"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'
},
method: 'POST',
url: '/'
}
porcellus
08/29/2022, 8:52 AMidanh.
08/29/2022, 8:53 AMporcellus
08/29/2022, 8:57 AMcredentials
to include
in the fetch options? (https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters)idanh.
08/29/2022, 9:04 AMapp.enableCors({
origin: ['http://localhost:3000'],
allowedHeaders: ['content-type', ...supertokens.getAllCORSHeaders()],
credentials: true,
});
idanh.
08/29/2022, 9:05 AMporcellus
08/29/2022, 9:06 AMporcellus
08/29/2022, 9:06 AMidanh.
08/29/2022, 9:11 AMlocalhost/:1 Access to fetch at 'http://localhost:4000/graphql' from origin 'http://localhost:3000' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
even though the origin i passed is only http://localhost:3000
idanh.
08/29/2022, 9:14 AMcors: {
credentials: true,
origin: true,
},
to GraphQLModule.forRoot
porcellus
08/29/2022, 9:15 AMidanh.
08/29/2022, 9:18 AMporcellus
08/29/2022, 9:18 AMidanh.
08/30/2022, 5:42 AM@Injectable()
export class GraphAuthGuard implements CanActivate {
async canActivate(context: ExecutionContext): Promise<boolean> {
const gqlCtx = GqlExecutionContext.create(context).getContext();
let err = undefined;
const resp = gqlCtx.req.res;
await verifySession()(gqlCtx.req, resp, (res) => {
err = res;
});
if (resp.headersSent) {
throw new STError({
message: 'RESPONSE_SENT',
type: 'RESPONSE_SENT',
});
}
if (err) {
return false;
}
return true;
}
}
so i can protect specific routes, but it throws the headersSent error, i'm assuming due to how the graphql requests behave ("Error: Cannot set headers after they are sent to the client")
does the plugin implementation implementation meant to replace that? was that the motivation to use the plugin?
if so, how would you split between authenticated routes to public ones? perhaps by requestContext.operation
on responseForOperation
instead of per resolver?porcellus
08/30/2022, 8:05 AMporcellus
08/30/2022, 8:09 AMidanh.
08/30/2022, 9:35 AMosmarpb97
09/22/2022, 10:04 PMosmarpb97
09/22/2022, 10:04 PMSuperTokens is an open source authentication solution offering features like: Different types of login: Email / password, Passwordless (OTP or Magic link based).
Powered by