kingmesal
11/26/2023, 9:51 PMrp_st
11/27/2023, 4:13 AMrp_st
11/27/2023, 4:13 AMrp_st
11/27/2023, 4:27 AMat_supertokens
11/27/2023, 5:09 AMsupertokens-node
.
The only known issue is OAuth compatibility with Apple. We're actively working on determining the best approach for full Cloudflare Workers support. We will keep you updated.kingmesal
11/27/2023, 2:29 PMrp_st
11/27/2023, 2:29 PMkingmesal
11/27/2023, 2:31 PMrp_st
11/27/2023, 2:33 PMrp_st
11/27/2023, 2:33 PMkingmesal
11/27/2023, 2:34 PMrp_st
11/27/2023, 2:34 PMrp_st
11/27/2023, 2:34 PMkingmesal
11/27/2023, 2:36 PMrp_st
11/27/2023, 2:36 PMlandturn
11/27/2023, 2:50 PMrp_st
11/27/2023, 2:51 PMlandturn
11/27/2023, 3:29 PMrp_st
11/27/2023, 3:29 PMrp_st
11/27/2023, 3:31 PMlandturn
11/27/2023, 3:31 PMrp_st
11/27/2023, 3:31 PMlandturn
11/27/2023, 3:32 PMrp_st
11/27/2023, 3:32 PMrp_st
11/27/2023, 3:34 PMlandturn
11/27/2023, 3:36 PMat_supertokens
11/28/2023, 5:45 AM"dev:start": "wrangler pages dev static --node-compat"
This would fix the error but the job is not done yet. supertokens-node
provides an API to support custom framework that can be utilized to support CF workers. If you are okay with using Hono then I already have a working for you [here](https://github.com/anku255/t4-app/tree/supertokens-auth/packages/api/src).
If Hono isn't your choice, you can either implement a similar solution or reach out for assistance.landturn
11/28/2023, 5:49 AMlandturn
11/28/2023, 5:50 AMlandturn
11/28/2023, 5:50 AMlandturn
11/28/2023, 5:50 AMrp_st
11/28/2023, 5:51 AMlandturn
11/28/2023, 5:55 AM~/src/gitlab.com/leed-ai/Services/cms/apps/backend/functions
> tree
.
βββ api
βββ _middleware.ts
βββ assets
βΒ Β βββ [assetId].ts
βΒ Β βββ create.ts
βΒ Β βββ favicon.ts
βΒ Β βββ index.ts
βββ company
βΒ Β βββ [companyId]
βΒ Β βΒ Β βββ provision.ts
βΒ Β βββ index.ts
βββ debug.ts
βββ invite
βΒ Β βββ [inviteId].ts
βββ labels
βΒ Β βββ [labelId].ts
βΒ Β βββ index.ts
βββ notifications
βΒ Β βββ index.ts
βββ page
βΒ Β βββ [pageId]
βΒ Β βΒ Β βββ comment.ts
βΒ Β βΒ Β βββ contentHtml.ts
βΒ Β βΒ Β βββ index.ts
βΒ Β βββ index.ts
βββ pagetypes
βΒ Β βββ [pageTypeId].ts
βΒ Β βββ index.ts
βββ schedule
βΒ Β βββ index.ts
βββ stats
βΒ Β βββ index.ts
βββ templates
βΒ Β βββ [templatePath].ts
βΒ Β βββ index.ts
βββ user
βββ [userId].ts
βββ index.ts
βββ invite
βΒ Β βββ [inviteId].ts
βββ login.ts
βββ me.ts
βββ session.ts
17 directories, 34 files
landturn
11/28/2023, 5:55 AMrp_st
11/28/2023, 5:57 AMrp_st
11/28/2023, 5:57 AMlandturn
11/28/2023, 6:09 AM_middleware.ts
file, or provide specialized functions that you chain together like this https://github.com/landonturner/supertokens-cloudflare/blob/d744982b0c7dc577758a7d1ec506c983d0e67539/functions/api/test.ts#L30.
https://developers.cloudflare.com/pages/platform/functions/middleware/rp_st
11/30/2023, 10:03 AMkingmesal
11/30/2023, 3:58 PM/functions
/endpoint1
/endpoint2
Each endpoint can use the pages middleware model that works like this:
javascript
export const requestHandler = async (context: EventContext<Env, string, SessionData>): Promise<Response> => {
const response = await context.env.FUNCTIONS.fetch(context.request);
return response;
};
export const onRequestPost = [authProvider, corsCheck, requestHandler];
export const onRequestOptions = [authProvider, corsCheck];
Then cloudflare pages uses the onRequest* to build the router.rp_st
11/30/2023, 4:07 PMPreParsedRequest
as shown here ( https://github.com/timothymiller/t4-app/blob/266b423a2b314ce9f165b9a3f747691f559b87d6/packages/api/src/supertokens/middleware.ts#L30C1-L30C1). You need to map the functions from context
to the respective functions required to create an instance of PreParsedRequest
.
You then create a CollectingResponse
instance (line 39).
Then you call the supertokens middleware (line 43) which either returns an error or a boolean (handled).
If error, then you essentially propagate that to your app's error handler. Else, if handled, it means our middleware handled the request and created a response (the response body, headers are in the instance of CollectingResponse
). This can happen if you call an API that our middleware exposes (like sign in, sign out etc). In this case, you have to create a response object as understood by your framework and transfer the body, headers, status code and cookies (line 50-54)
In case not handled, it means that it's a request to one of your APIs, and you pass it on to your other APIs, or return a 401 (i think in your case, it should be 401 since the auth middleware will only run if you query /auth/* anyway.rp_st
11/30/2023, 4:09 PMPreParsedRequest
and CollectingResponse
objects and pass it to it. The only tricky part is that sometimes, getSession
can modify the access token in the cookies, so that needs to be returned as part of the response too.James
03/27/2024, 12:55 PMrp_st
03/27/2024, 12:56 PMJames
03/27/2024, 12:57 PMat_supertokens
03/27/2024, 1:03 PM