Skip to content

Commit

Permalink
refactor(client): configurable baseURL
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienZ committed Oct 19, 2024
1 parent 0ea8e6a commit 3846919
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ Example: `~/app.vue`
<script setup lang="ts">
const { loggedIn, user, session, clear, fetch: fetchSession } = useUserSession();
const authClient = getSlipAuthClient();
const authClient = getSlipAuthClient({
baseURL: useRequestURL().origin,
});
async function seedUser() {
const email = `user-${Math.random()}@email.com`;
const password = "password";
Expand Down
4 changes: 3 additions & 1 deletion playground/pages/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@

<script setup lang="ts">
const { session, user, fetch: fetchSession } = useUserSession();
const authClient = getSlipAuthClient();
const authClient = getSlipAuthClient({
baseURL: useRequestURL().origin,
});
const askEmailVerificationRequest = await useLazyAsyncData(() => authClient.askEmailVerificationCode(), {
immediate: false,
Expand Down
5 changes: 2 additions & 3 deletions src/runtime/nuxt/app/utils/authClient.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import type { SlipAuthCore } from "../../../core/core";
import { routerRecord } from "../../../h3/routerRecord";
import { ofetch } from "ofetch";
import { useRequestURL } from "#imports";

import type loginHandler from "../../../h3/routes/login.post";
import type registerHandler from "../../../h3/routes/register.post";
import type askEmailVerificationCodeHandler from "../../../h3/routes/ask-email-verification.post";
import type verifyEmailVerificationCodeHandler from "../../../h3/routes/verify-email-verification.post";

export function getSlipAuthClient() {
export function getSlipAuthClient(config: { baseURL: string }) {
const httpClient = ofetch.create({
baseURL: useRequestURL().origin,
baseURL: config.baseURL,
});

return {
Expand Down

0 comments on commit 3846919

Please sign in to comment.