Is there a utility function for determining the status code to send to a client when using Next.js a...
n
Is there a utility function for determining the status code to send to a client when using Next.js and the
supertokens-auth-react
SDK? The route will return
200
for everything. I am looking for a
getRoutingComponent
equivalent e.g.
getStatusCodeForRoute
that I can call within
getServerSideProps
.
r
hey @n1ru4l i don't quite understand this question. Can you maybe explain more?
n
If I visit
/auth/kwjhdweljhklwhjrdiwehrflwekhrkwer
I get status code 200
But it should be 404
r
can i see the code for middleware setup in the nextjs api layer?
n
I am not talking about the API route, I am talking about the UI route
r
right. Can i see the code for how you are using our getRoutingCOmponent funiction?
We have a function called
canHandeRoute
see here: https://github.com/supertokens/next.js/blob/canary/examples/with-supertokens/pages/auth/%5B%5B...path%5D%5D.tsx#L14 Is this what will solve your issue?
n
yes!
thank you
Can this function be called on the serverside though?
r
i don't think so. It requires supertokens.init (from the frontend lib) which happens only ont he frontend.
n
hmm
So it does not solve my problem 😄
r
yeaaa, then im not sure that we have some function that can help you. Maybe think of another way to solve it
n
Copy code
import { env } from '@/env/backend';

const supertokenRoutes = new Set([
  '/auth/verify-email',
  '/auth/reset-password',
  '/auth/login',
  '/auth',
]);

if (env.auth.github) {
  supertokenRoutes.add('/auth/callback/github');
}
if (env.auth.google) {
  supertokenRoutes.add('/auth/callback/google');
}
if (env.auth.okta) {
  supertokenRoutes.add('/auth/callback/okta');
}
if (env.auth.github) {
  supertokenRoutes.add('/auth/callback/github');
}
if (env.auth.organizationOIDC) {
  supertokenRoutes.add('/auth/oidc');
}

export function canHandleRouteServerSide(path: string) {
  return supertokenRoutes.has(path);
}
I came up with something custom based on our configuration 🙂
r
yea, that works!
n
The full code for anyone interested 😇 https://github.com/kamilkisiela/graphql-hive/pull/2705/files
10 Views