<@498057949541826571> Hey guys, Do you have an SDK for Remix?
j
@rp_st Hey guys, Do you have an SDK for Remix?
r
hey @joe80813 the integration guide is coming very soon (1 few days). @Darko can help here.
j
1 more day?
r
sorry, i meant few more days
j
Is that an SDK? right now you don't support Remix yet?
r
we do support remix. You can use our supertokens-auth-react and supertokens-node sdk to add supertokens to a remix app. Whats missing is an example app / guide on how to do that, which is coming soon
j
Thank you. Hoping to see the guide very soon πŸ™‚
d
hey @joe80813
if you have any specific questions for integrating SuperTokens with Remix, feel free to ping me πŸ™‚
I'd be happy to help
j
Thanks Darko. Just wanted to ask if you have a guide on how to set it up from scratch? πŸ™‚ I'm using Remix Vite Express. Thank you.
d
not in writing, no
the integration example app is coming soon though
I'll make sure to update the readme with Remix specifics you can use
in fact, the integration example we're making for Remix is pretty close to Next (app router) conceptually
j
Got it. Thank you πŸ™‚
@Darko Which of these looks correct? https://github.com/mawentowski/supertokens_TPEP_remix https://github.com/ITenthusiasm/remix-supertokens or if you could share some repo πŸ™‚
r
you can see this: https://github.com/supertokens/create-supertokens-app/pull/98. It's still WIP though, but 90% there,.
j
Thanks a lot!
@Darko It would be great to convert this to Remix Vite πŸ™‚ https://remix.run/docs/en/main/future/vite
npx create-remix@latest --template remix-run/remix/templates/express
d
yeah, thought about it too
seeing that they moved to vite, it's certainly a good idea
I'll see what I can do πŸ™‚
j
How do you call the
env
here? Still using
process.env...
? Doesn't seem to work
d
there's a workaround
basically, you can sorta "cheat" on it via vite
PR coming soon πŸ˜„
j
@Darko Separate PR? Could you share some code here. Currently testing your work πŸ˜‰
d
sorry, meant commit over the PR πŸ˜„
okay, pull the latest from feat/add-remix πŸ˜„
or run the CLI, that should work too
j
Sure.
So how do you call the
env
?
btw, I think you can remove the
remix.config
?
d
yeah
kept it for reference to make sure I don't forget to port something
as for env
vite.config.ts, line 18
define: { "process.env": {}, },
overrides it
j
Is this correct? define: { "process.env": { TEST_URL: process.env.TEST_URL, }, },
d
yep, should be fine in theory
if it's not, we'll need to account for both import.meta and process.env based on the integration we're in
j
yeah it seems it still doesn't work
@Darko I'm having an error like `Error: You made a POST request to "/supertokens/session/refresh" but did not provide an
action
for route "routes/supertokens.$", so there is no way to handle the request.` Do you encounter this also?
d
hmph
nope, not really
what lead you to this?
i.e. what did you try to do?
j
Well just copied your latest updates. Let me check if I miss something hmm
d
do you have it somewhere public?
j
Nevermind. Fixed it πŸ™‚ Btw, I think you should replace your import of
react-router-dom
to
@remix-run/node
or
@remix-run/react
Saw it in some of your files
d
hmph, right
will do
thanks for the catch
j
Random Question: Do we need to write some supertokens code in the
_index.tsx
besides the purpose of displaying user data? I tried removing it and it still works. It still redirects to the login page when unauthenticated. I ask this question because if an app has multiple pages/routes, do we need to declare this in every page?
d
ah right, having a middleware
well
remix, AFAIK, doesn't have a notion of a middleware built-in
they do have an RFC open for it, but it's nowhere near production ready
which means, you'd have to get creative for checking user auth on each route
this kinda describes it
it's an extra line in each file pretty much
j
Yes. that's right. They don't have it yet. But what's the purpose of your code in the
root.tsx
though?
Copy code
<SuperTokensWrapper>
                    {isUnprotectedRoute ? (
                        <Outlet />
                    ) : (
                        <SessionAuth>
                            <Outlet />
                        </SessionAuth>
                    )}
                </SuperTokensWrapper>
d
ah right
something we copied over from next, as a starting point (the idea, anyway)
basically
auth routes should be accessible regardless of whether the user is authenticated or not
the rest are authenticated routes
not sure if that translates too well to remix-land
j
But that alone works. I tried removing code related to supertokens in the
_index.tsx
and it still redirected me to the auth page when unautheticated πŸ™‚
d
the loader code, you mean?
or this:
j
Yes. that one.
d
hmph
why do we have that in there
let me dig up a bit πŸ˜„
j
Thank you. and also the
<SessionAuthForRemix>
in the return.
d
so thinking out loud
each route first goes through the server
if the server catches a route being configured as authenticated and no auth present, it will redirect to auth
straight from the server
and the thing we have over in Home is client-side
r
we have that in there cause if the claims are invalid, then the on the frontend will redirect to the right place (for example, emial verification page in case the email verification claims failed)
and is used to refresh the session since the access token is there, but it's just expired
d
oh right
j
All right. Thanks guys. So we'll have to do this in every page/route then? πŸ™‚
r
Yea. Everytime you want to do SSR
j
Alright. Are there anything else you're working on the PR? Seems all the issues are resolved. Probably fix the
env
? πŸ™‚
d
pending a review, it's going in the CLI
so you'll have a working CLI example soon
what's with the env? the process thing?
j
Yeah. this doesn't seem to work. Can you try on your end? I have an .
env
file:
Copy code
SUPERTOKENS_CONNECTION_URI=https://s......
SUPERTOKENS_API_KEY=v.....
then on the
vite.config
, I have this
Copy code
import { vitePlugin as remix } from "@remix-run/dev";
import { installGlobals } from "@remix-run/node";
import { flatRoutes } from "remix-flat-routes";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

installGlobals();

export default defineConfig({
  server: {
    port: 3000,
  },
  plugins: [
    remix({
      ignoredRouteFiles: ["**/*.css"],
      routes: async (defineRoutes) => {
        return flatRoutes("routes", defineRoutes);
      },
    }),
    tsconfigPaths(),
  ],
  define: {
    "process.env": {
      SUPERTOKENS_CONNECTION_URI: process.env.SUPERTOKENS_CONNECTION_URI,
      SUPERTOKENS_API_KEY: process.env.SUPERTOKENS_API_KEY,
    },
  },
});
How should I call this on a file? Like this?
Copy code
export let backendConfig = (): TypeInput => {
    return {
        supertokens: {
            connectionURI: process.env.SUPERTOKENS_CONNECTION_URI,
            apiKey: process.env.SUPERTOKENS_API_KEY
        },
        appInfo,
        recipeList: [
            PasswordlessNode.init({
                contactMethod: "EMAIL_OR_PHONE",
                flowType: "USER_INPUT_CODE_AND_MAGIC_LINK",
            }),
            SessionNode.init(),
            Dashboard.init(),
            UserRoles.init(),
        ],
        isInServerlessEnv: true,
        framework: "custom",
    };
};
d
will do, first chance I get
j
In
vite.config.ts
, what's the purpose of
installGlobals();
?
node polyfills
we were using remix serve
but it still seemed to complain about missing node stuff
one I installed added installGlobals
the errors went away
j
Hmm. Didn't encounter that error even after removing
installGlobals
. This is my
entry.server.ts
Btw, it seems you don't have
entry.client.ts
but I don't think having that does matter.
d
not in this case, no
that's weird... could have been a coincidence
will investigate once I get some time
j
Ok thank you
Did you have a chance to look at the env thing? I removed this in the
vite.config.ts
, and the page that doesn't have the supertokens code worked. But if I added it back, the page that has the supertokens code in it worked, while the other pages that don't have the supertokens code don't work.
Copy code
define: {
    "process.env": {},
 },
d
πŸ€”
yeah, we might wanna have a deeper look at that
since they went with vite and es modules, and I don't think we're covering that currently
we'll have to maybe change something
j
This code overrides the process.env being called on other files. define: { "process.env": {}, },
Why if we just remove this code. Why it won't work with pages that have supertokens? hmm define: { "process.env": {}, },
But anyway, if you could have a chance to fix the environment since it's quite important to us, that would be great. Thank you
d
hmph
I was getting a process is undefined error because of vite
vite uses import.meta by default, opposed to process.env
yet, Remix in their docs states that process.env is they way to get env vars
so I'm kinda at a loss here
not sure which one is correct
j
@Darko Seems to work now. Tried this one. https://github.com/vitejs/vite/issues/1973#issuecomment-815695512 But another person commented: "This works for me while development but after build process becomes undefined." I haven't tried building it though https://github.com/vitejs/vite/issues/1973#issuecomment-820343918 and btw, I just used
process.env
not
import.meta.env
d
I suspect there's something missing in the docs for porting to vite from the remix compiler
I'll investigate
j
Hey guys, I have some questions: 1. Are we using
routes
>
sessioninfo.$.tsx
? What's the purpose of it? 2. Is
apiBasePath
in your example is the
routes
>
supertokens.$.tsx
? What's the purpose of it? 3. Is
websiteBasePath
in your example is the
routes
>
auth.$.tsx
? What's the purpose of it? Is it the path where our login UI will be rendered
r
1. Its just an example api 2. It's the route which uses our middleware and exposes the API for the frontend. 3. Yes, path where our pre built UI ui will be rendered
j
Oh ok. So we can remove
sessioninfo.$.tsx
?
r
yup, you can
d
first one seems to be a build issue
some kind of an interop thing between commonjs and ES
we have a method called
getInstanceOrThrowError
on
SessionRecipe
using that throws an error, so we had to resort to this for the demo
on the user context thing, feel free to change that according to your needs
here are the docs for it
j
Alright, will take a look at it. Thanks for the quick reply.
r
which version of supertokens-web-js are you using?
and which version of supertokens-auth-react>
j
I only installed these two "supertokens-auth-react": "^0.39.0", "supertokens-node": "^17.0.2"
r
can i see your package-lock.json?
is there any lock file? yarn lock? Anything? I need to see which version of supertokens-web-js you have (it's a dependency of supertokens-auth-react)
j
Let me find it. I don't need to install
supertokens-web-js
, right?
r
you don't.
i mean, you may.. depends on your package manage
so you can also get supertokens-web-js
and then this error should go away
j
I can't seem to find any lock file. But I saw a proj on our turborepo that has this
"supertokens-web-js": "^0.9.1"
Problems it conflicts with mine?
r
u need to get 0.10.0 version of supertokens-web-js version
j
But it's not connected to my proj though. Maybe I'll just install "supertokens-web-js": "^0.10.0" on my own proj?
r
i guess, yea
not me. Sorry
j
Sorry but can you further elaborate this? Cause I'm confused since we already have a checker if you're authenticated or not in the
root.tsx
. Thank you.
r
a session may exist, but the claims may be invalid based on your config. For example, if you want email verification always, the session may exists for an unverified email, in which case the claim error will come
j
So in simpler terms, imagine logging in to the app that requires email verification. You might be able to log in and create a session, but you won't be able to access certain features until you verify your email? Is this correct?
r
Yea.
j
What other scenarios are there besides this one, or is it just this alone?
r
Depends on your configurations. If you have added MFA, or if you have added some other global claim validator.
Otherwise, besides this, nothing else
And this also, it assumes yhat you have configured email verification in REQUIRED mode. Otherwise this won’t be applicable either
j
Thanks. We can't include this condition in the
root.tsx
?
r
Not sure. But it’s included whenever you call the session verification function
j
r
whats the vlaue of the config you have set?
j
This is the
frontend.tsx
Copy code
import type { SuperTokensConfig } from "supertokens-auth-react/lib/build/types";
import Session from "supertokens-auth-react/recipe/session/index.js";
import ThirdPartyEmailPasswordReact from "supertokens-auth-react/recipe/thirdpartyemailpassword/index.js";
import { ThirdPartyEmailPasswordPreBuiltUI } from "supertokens-auth-react/recipe/thirdpartyemailpassword/prebuiltui.js";
import { appInfo } from "./appInfo";

export const frontendConfig = (): SuperTokensConfig => {
    return {
        appInfo,
        recipeList: [
            ThirdPartyEmailPasswordReact.init({
                signInAndUpFeature: {
                    providers: [ThirdPartyEmailPasswordReact.Google.init()],
                },
            }),
            Session.init(),
        ],
    };
};

export const PreBuiltUIList = [ThirdPartyEmailPasswordPreBuiltUI];
r
can you use our CLI to generate a new remix app and see the config from there?
im not too sure as to why this issue would happen in your app
j
Can you share the link?
r
use
npx create-supertokens-app@latest
and follow the instrs
j
Alright
Do you support bun I guess?
r
i think yea
j
It doesn't highlight that error when created via your cli. Maybe we have a stricter linting?
r
Hmm. Maybe. If you can replicate this issue in our demo app, we will be happy to sort it out
j
I experience oftentimes blank white page. However when I commented out this code in the
root.tsx
, it got fixed. I also have to manually add
/auth
to the url too.
Copy code
<SuperTokensWrapper>
{isUnprotectedRoute ? (
    <Outlet />
) : (
    <SessionAuth>
        <Outlet />
    </SessionAuth>
)}

<ScrollRestoration />
<Scripts />
</SuperTokensWrapper>
r
Can you reproduce it in our demo app?
j
I'll try but your demo app works well. It's an intermittent issue
31 Views