i've updated to v12, https://github.com/supertok...
# support-questions
e
i've updated to v12, https://github.com/supertokens/supertokens-web-js/pull/43 Can I remove the sync versions?
n
@EdwinN1337 Sorry that was my mistake, that PR has been merged but the SDK update hasnt been released yet (in the internal testing phase) Ill update here once its released
e
Okey, no problem thanks
I;m getting this weird error, when refreshing page
any idea why doesSessionExist = undefined?
n
How are you importing it?
e
import { doesSessionExist, getAccessTokenPayloadSecurely, signOut } from 'supertokens-website'
calling it in a useEffect so no ssr
its a next app in
_app.tsx
if (typeof window !== 'undefined') { supertokens.init(frontendConfig().appInfo) }
n
Are you calling supertokens.init before that?
e
before
Copy code
js

if (typeof window !== 'undefined') {
  supertokens.init(frontendConfig().appInfo)
}


function MyApp({ Component, pageProps, err }: App) {
  return (
    <QueryClientProvider client={queryClient}>
      <ChakraProvider theme={THEME}>
        <SearchStateProvider>
          <Layout>
            <Component {...pageProps} err={err} />
          </Layout>
          {/* <ReactQueryDevtools /> */}
        </SearchStateProvider>
      </ChakraProvider>
    </QueryClientProvider>
  )
}
Inside I call
getUser()
n
Can I see the full code for this snippet? (including the imports)
You can remove any keys etc
e
Copy code
js
import create from 'zustand'
import { combine, devtools } from 'zustand/middleware'
import { UserState } from './types/useUserStore.types'
import { doesSessionExist, getAccessTokenPayloadSecurely, signOut } from 'supertokens-website'
import { getUserData } from './helpers/useUserStore.helpers'

const defaultValues: UserState = {
  user: null,
  isLoggedIn: false,
}

export const useUserStore = create(
  devtools(
    combine(defaultValues, (set) => ({
      getUser: async () => {
        const validSession = await doesSessionExist()

        if (!validSession) {
          return set(() => defaultValues)
        }
n
No I meant the one where you call supertokens.init
e
Ah sorry
Copy code
js
import { AppProps } from 'next/app'
import { QueryClient, QueryClientProvider } from 'react-query'
import Layout from 'ui-dashboard/containers/Layout/Layout'
import { SearchStateProvider } from 'ui-dashboard/context/SelectedStoreState'
import supertokens from 'supertokens-website'
import { frontendConfig } from 'dashboard/config/frontendConfig'
import { ChakraProvider } from '@chakra-ui/react'
import 'ui-dashboard/styles/global.css'
// import { ReactQueryDevtools } from 'react-query-devtools'
import THEME from 'ui-dashboard/styles/theme'
const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      refetchOnWindowFocus: false,
    },
  },
})
type App = AppProps & { err: any }

if (typeof window !== 'undefined') {
  supertokens.init(frontendConfig().appInfo)
}


function MyApp({ Component, pageProps, err }: App) {
  return (
    <QueryClientProvider client={queryClient}>
      <ChakraProvider theme={THEME}>
        <SearchStateProvider>
          <Layout>
            <Component {...pageProps} err={err} />
          </Layout>
          {/* <ReactQueryDevtools /> */}
        </SearchStateProvider>
      </ChakraProvider>
    </QueryClientProvider>
  )
}

export default MyApp
n
Can you enable debug logs on the frontend and post the output
e
Copy code
js
com.supertokens {t: "2022-06-20T13:01:11.890Z", message: "doRequest: User's http call ended", supertokens-website-ver: "11.0.2"}
logger.js?100b:30 com.supertokens {t: "2022-06-20T13:01:11.891Z", message: "getIdRefreshToken: called", supertokens-website-ver: "11.0.2"}
logger.js?100b:30 com.supertokens {t: "2022-06-20T13:01:11.892Z", message: "getIdRefreshToken: returning EXISTS: 96d42b5a-9d54-4899-bfb1-c3fa5e3f8992", supertokens-website-ver: "11.0.2"}
n
There should be logs that are printed when your app starts up
e
It's like, I call it before initializing
whichi is weird, since i place the init in
_app.tsx
, should be the first function to be initialized
It's not a huge problem btw
n
Its possible that the part where youre calling the function runs on both the server side and client side, and since supertokens.init only runs on the client side it results in an error
e
cuz, user in prod won't see it and after few ms its initialized
i call it on client side hmm,
i'll ignore it for now, no big deal internal app 😉
n
What stack are you using? Ill check if I can recreate it
e
Ah i've updated
to v12
v11 didnt give ts err? maybe its related not sure
n
Right, v11 didnt have any parameters to that function so it probably didnt complain
That shouldnt cause the undefined error though
e
true
it doesnt
next.js
n
Cool ill look into it, but it looks like supertokens.init didnt work correctly (either because it didnt run before you used the function or because something else broke)
e
Yeah, no hurry cuz it got run twice
Probably on server > client
user in prod won't notice
once they login, its already initialized
n
Fair, either way ill keep you updated if I find anything
e
Thanks again hehe
3 Views