-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(imports): Add minimal stubs useAuth and useAuthState imports
WHne nuxt-auth module is disabled all #auth imports were failing. For mocking and testing this presented a situation which was impossible to handle properly. This commit adds a stub for these imports on the client side when the module is disabled, opening a way to mock the modules properly.
- Loading branch information
Showing
3 changed files
with
88 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { ref, readonly } from 'vue' | ||
import { | ||
CommonUseAuthStateReturn, | ||
SignOutFunc, | ||
SignInFunc, | ||
// SessionStatus, | ||
GetSessionFunc | ||
} from '../../types' | ||
import { useAuthState } from './useAuthState' | ||
|
||
export const useAuth = (): CommonUseAuthStateReturn<null> => { | ||
const { | ||
data, | ||
status, | ||
lastRefreshedAt | ||
} = useAuthState() | ||
|
||
const getters = { | ||
status, | ||
data: readonly(data), | ||
lastRefreshedAt: readonly(lastRefreshedAt), | ||
loading: ref(false), | ||
refresh: () => null, | ||
_internal: { | ||
baseURL: '' | ||
} | ||
} | ||
|
||
const getSession:GetSessionFunc<any> = async (_) => { | ||
return await data.value | ||
} | ||
const signIn:SignInFunc<unknown, any> = async (_) => {} | ||
const signOut:SignOutFunc = async () => {} | ||
|
||
const actions = { | ||
getSession, | ||
signIn, | ||
signOut, | ||
getProviders: () => [], | ||
getCsrfToken: () => '' | ||
} | ||
|
||
return { | ||
...getters, | ||
...actions | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ref, readonly } from 'vue' | ||
import { CommonUseAuthStateReturn } from '../../types' | ||
import { makeCommonAuthState } from '../commonAuthState' | ||
|
||
export const useAuthState = (): CommonUseAuthStateReturn<null> & { | ||
token: ReturnType<typeof ref> | ||
refreshToken: ReturnType<typeof ref> | ||
} => { | ||
return { | ||
...makeCommonAuthState<null>(), | ||
token: readonly(ref('')), | ||
refreshToken: readonly(ref('')) | ||
} | ||
} | ||
export default useAuthState |