Hey, I'm trying to set up supertokens with next.js...
# support-questions-legacy
d
Hey, I'm trying to set up supertokens with next.js 13, but am getting this error when visiting `/api/auth`:
Copy code
tsx
TypeError: Cannot read properties of null (reading 'useEffect')

src/pages/api/auth/[[...path]].tsx (13:14) @ Auth
  11 | 
  12 | export default function Auth(): JSX.Element {
> 13 | useEffect(() => {
     |          ^
  14 |     if (SuperTokens.canHandleRoute() === false) {
  15 |         SuperTokens.redirectToAuth({
  16 |             redirectBack: false,
r
Hey.
You can’t use useEffect in the api folder. Since that runs on the backend and not frontend.
s
ah ok, thanks @rp_st
also if I'm using next as my frontend and nest.js as my backend, does that change how I implement the frontend supertokens code? Or can I just implement both like how the guides suggest?
i.e. is there any further work I have to do to integrate the frontend (next.js) and backend (nest.js) supertokens code?
@rp_st hmm I'm now getting
Copy code
tsx
Error: SuperTokens must be initialized before calling this method.

Source
src/pages/auth/[[...path]].tsx (13:12) @ SuperTokens

  11 | export default function Auth(): JSX.Element {
  12 | useEffect(() => {
> 13 |     if (SuperTokens.canHandleRoute() === false) {
     |        ^
  14 |         SuperTokens.redirectToAuth({
  15 |             redirectBack: false,
  16 |         });
I've initialized SuperTokens in a layout in
src/app/foo/layout.tsx
, but supertokens doesn't seem to recognize that
r
you can follow the frontend setup for nextjs and backend setup for nestjs. Please make sure that you have initialised supertokens before using any of its functions - the error indicates that you haven't initialised supertokens at the right place - you want to do it in the global scope in your app's _app.tsx file