Skip to content

Commit

Permalink
replaced router with navigateTo
Browse files Browse the repository at this point in the history
  • Loading branch information
manchenkoff committed Sep 21, 2023
1 parent e0c33a2 commit f47002e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/runtime/composables/useSanctumAuth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { computed } from 'vue';
import { useSanctumClient } from './useSanctumClient';
import { useSanctumUser } from './useSanctumUser';
import { useRoute, useRouter, useRuntimeConfig } from '#app';
import { navigateTo, useRoute, useRuntimeConfig } from '#app';
import { SanctumOptions } from '~/src/types';

/**
Expand All @@ -12,7 +12,6 @@ import { SanctumOptions } from '~/src/types';
export const useSanctumAuth = <T>() => {
const user = useSanctumUser<T>();
const client = useSanctumClient();
const router = useRouter();
const options = useRuntimeConfig().public.sanctum as SanctumOptions;

const isAuthenticated = computed(() => {
Expand Down Expand Up @@ -45,14 +44,12 @@ export const useSanctumAuth = <T>() => {
const requestedRoute = route.query.redirect as string | undefined;

if (requestedRoute) {
await router.push(requestedRoute);

return;
return await navigateTo(requestedRoute);
}
}

if (options.redirect.onLogin) {
await router.push(options.redirect.onLogin);
return await navigateTo(options.redirect.onLogin);
}
}

Expand All @@ -69,7 +66,7 @@ export const useSanctumAuth = <T>() => {
user.value = null;

if (options.redirect.onLogout) {
await router.push(options.redirect.onLogout);
return await navigateTo(options.redirect.onLogout);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/runtime/httpFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
useCookie,
useRequestEvent,
useRequestHeaders,
useRouter,
useRuntimeConfig,
navigateTo,
} from '#app';
import { SanctumOptions } from '../types';

Expand All @@ -15,7 +15,6 @@ export const SECURE_METHODS = new Set(['post', 'delete', 'put', 'patch']);
export function createHttpClient(): $Fetch {
const options = useRuntimeConfig().public.sanctum as SanctumOptions;
const event = useRequestEvent();
const router = useRouter();

/**
* Request a new CSRF cookie from the API and pass it to the headers collection
Expand Down Expand Up @@ -107,7 +106,7 @@ export function createHttpClient(): $Fetch {

// follow redirects on client
if (response.redirected) {
await router.push(response.url);
await navigateTo(response.url);
}
},
};
Expand Down

0 comments on commit f47002e

Please sign in to comment.