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

bug/LBGG-590: Persistent login #616

Merged
merged 3 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion composables/useCurrentUser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useCookie } from 'nuxt/app'
import type { UserViewModel } from 'lib/api/data-contracts'
import type { CookieRef } from 'nuxt/app'

Expand Down
1 change: 0 additions & 1 deletion composables/useSessionToken.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useCookie } from 'nuxt/app'
import type { CookieRef } from 'nuxt/app'

export function useSessionToken(): CookieRef<string> {
Expand Down
19 changes: 19 additions & 0 deletions vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ const fetchMock = createFetchMock(vi)
// sets globalThis.fetch and globalThis.fetchMock to our mocked version
fetchMock.enableMocks()

const cookies = reactive<{ [key: string]: any }>({})
interface CookieOptions {
default?: () => any
}

export const useCookieMock = vi.fn((key: string, opts?: CookieOptions) => {
const cookie = toRef(cookies, key)
if (cookie.value === undefined && opts?.default) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if both cookie and opts.default don't have values? Won't we be returning an undefined ref?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's actually just how regular cookies work anyway.

const initialValue = opts.default()
if (isRef(initialValue)) {
cookies[key] = initialValue
return initialValue as Ref<any>
}
cookie.value = initialValue
}
return cookie
})
vi.stubGlobal('useCookie', useCookieMock)

// Stolen from here:
// https://zenn.dev/ninebolt6/articles/cadc924cb2416d
const payload = reactive<{ state: Record<string, any> }>({
Expand Down
Loading