-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: desctruct project and add pending current session
- Loading branch information
Showing
8 changed files
with
116 additions
and
72 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
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
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,37 @@ | ||
import type {ModuleOptions, ModuleOptionsEndpointConfig} from "../module"; | ||
import type {UseLocalAuthFetchConfig, UseLocalAuthResponse} from "./types"; | ||
import {callWithNuxt, useNuxtApp, useRuntimeConfig} from "#app"; | ||
import useLocalAuthState from "./composables/useLocalAuthState"; | ||
import useUtils from "./composables/useUtils"; | ||
|
||
const { trimStartWithSymbol } = useUtils(); | ||
|
||
export async function getContext() { | ||
const nuxt = useNuxtApp(); | ||
const options = (await callWithNuxt(nuxt, useRuntimeConfig)).public.localAuth as ModuleOptions; | ||
const state = await callWithNuxt(nuxt, useLocalAuthState); | ||
|
||
return { | ||
options, | ||
state | ||
}; | ||
} | ||
export async function fetch<T extends UseLocalAuthResponse>( | ||
endpoint: ModuleOptionsEndpointConfig, | ||
_config: UseLocalAuthFetchConfig | ||
): Promise<T> { | ||
const config: UseLocalAuthFetchConfig = { | ||
withToken: false, | ||
..._config, | ||
} | ||
const { state: { token, origin} } = await getContext(); | ||
|
||
return await $fetch( | ||
`${origin}/${trimStartWithSymbol(endpoint.path, '/')}`, | ||
{ | ||
method: endpoint.method, | ||
body: config.body, | ||
headers: config.withToken ? { 'Authorization': token.value! } : {} | ||
} | ||
); | ||
} |
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