Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem refresh page #982

Open
memellow85 opened this issue Jan 14, 2025 · 2 comments
Open

Problem refresh page #982

memellow85 opened this issue Jan 14, 2025 · 2 comments
Labels
bug A bug that needs to be resolved pending An issue waiting for triage

Comments

@memellow85
Copy link

Environment


  • Operating System: Darwin
  • Node Version: v20.17.0
  • Nuxt Version: 3.15.1
  • CLI Version: 3.20.0
  • Nitro Version: 2.10.4
  • Package Manager: [email protected]
  • Builder: -
  • User Config: alias, app, srcDir, debug, dev, devServer, ssr, devtools, modules, auth, vite, compatibilityDate
  • Runtime Modules: @sidebase/[email protected]
  • Build Modules: -

Reproduction

I have this endpoints:

http://example.com/user/token -> response -> { access_token: "", refresh_token: "" }
http://example.com/user/token-refresh -> body -> { refresh_token: "" }  -> response -> { access_token: "", refresh_token: "" }
http://example.com/user/my-user -> response -> { id: "", name: "" }

My configuration is this:

auth: {
    isEnabled: true,
    disableInternalRouting: true,
    disableServerSideAuth: true,
    baseURL: 'http://example.com',
    provider: {
      type: 'local',
      pages: {
        login: '/login',
      },
      endpoints: {
        signIn: { path: '/user/token', method: 'post' },
        signOut: false,
        signUp: false,
        getSession: { path: '/user/my-user', method: 'get' },
      },
      token: {
        signInResponseTokenPointer: '/access_token',
      },
      refresh: {
        isEnabled: true,
        endpoint: { path: '/user/token-refresh', method: 'post' },
        refreshOnlyToken: false,
        token: {
          signInResponseRefreshTokenPointer: '/refresh_token',
          refreshResponseTokenPointer: '/access_token',
          refreshRequestTokenPointer: '/refresh_token',
        },
      },
      session: {
        dataType: {
          id: 'string',
          name: 'string',
        },
        dataResponsePointer: '/',
      },
    },
    sessionRefresh: {
      enablePeriodically: false,
      enableOnWindowFocus: true,
    },
    globalAppMiddleware: {
      isEnabled: true,
      addDefaultCallbackUrl: false,
    },
  },

My files .vue:
index.vue

<script setup lang="ts">
const { signOut, status, data } = useAuth()

const test = () => {
  signOut({ callbackUrl: '/login' })
}
</script>

<template>
  <div>
    {{ status }}<br />
    {{ data }}<br />
    <button @click="test">logout</button>
  </div>
</template>

login.vue

<script setup lang="ts">
const { signIn, status, data } = useAuth()

const username = ref('user')
const password = ref('password')

definePageMeta({
  auth: {
    unauthenticatedOnly: true,
    navigateAuthenticatedTo: '/'
  }
})

const submit = (): void => {
  signIn({ name: username.value, password: password.value }, { callbackUrl: '/' })
}
</script>

<template>
  <div>
    {{ status }}<br />
    {{ data }}<br />
    <input v-model="username" type="text" />
    <input v-model="password" type="password" />
    <button @click="submit()">sign in</button>
  </div>
</template>

Describe the bug

Hi, I have a problem when refresh page after login... After login I go to index.vue page but if I refresh page... I go always in login.vue... why?

Thanks a lot

Additional context

No response

Logs

No response

@memellow85 memellow85 added bug A bug that needs to be resolved pending An issue waiting for triage labels Jan 14, 2025
@daniel-ness
Copy link

Had a similar issue on a new project. The solution for me was to disable SSR mode in Nuxt

@memellow85
Copy link
Author

I have already set ssr to false.
Probably the problem is because when the page is refreshed the status is loading... the status is changed after the getSession I think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug that needs to be resolved pending An issue waiting for triage
Projects
None yet
Development

No branches or pull requests

2 participants