Skip to content

Problem setting awaited value to state #2058

Discussion options

You must be logged in to vote

Fixed by updating the type provided to the useAuthService to also return a unwrapref<T> instead of just <T>

export const useAuthStore = <T = AuthUserResource>({ typeGuard = isAuthUserResource }: { typeGuard?: <T>(user: unknown) => user is T } = {}) => {
  
  const service = useAuthService<UnwrapRef<T>>({ typeGuard })

  return defineStore('auth', {
    state: () => ({
      user: {} as T
    }),
    actions: {
      set(u: UnwrapRef<T>) {
        this.user = u
      },
      async login(body: LoginRequest) {
        const data = await service.login({ body })
        if (typeGuard<T>(data)) this.user = data
      }
    },
    getters: {
      isAuthenticated: (state) => typeGuard<T>(state.u…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by andredewaard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant