Skip to content

Commit 48ad0f6

Browse files
Benoit NgoNgob
authored andcommitted
chore(proxy): add use stream
chore(auth): change auth-store into a setup store
1 parent 345aa6d commit 48ad0f6

File tree

21 files changed

+90
-108
lines changed

21 files changed

+90
-108
lines changed

apps/front/src/app.vue

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div>
33
<NuxtErrorBoundary @error="mHandleError">
4-
<NuxtLayout v-if="!isPendingAuth || authStore.isAuthenticated">
4+
<NuxtLayout v-if="!isMePending || isAuthenticated">
55
<NuxtPage />
66
</NuxtLayout>
77
</NuxtErrorBoundary>
@@ -10,6 +10,7 @@
1010
<script setup lang="ts">
1111
import { watchEffect } from "vue";
1212
import { useAuthUser } from "~/store/auth";
13+
import { storeToRefs } from "pinia";
1314
1415
const authStore = useAuthUser();
1516
@@ -18,23 +19,21 @@ const route = useRoute();
1819
const mHandleError = (e: unknown) => {
1920
logger.error("Primary error boundary", e);
2021
};
21-
const isPendingAuth = computed(() => authStore.isPending);
22+
const { isAuthenticated, isMePending, authUrl } = storeToRefs(authStore);
2223
// Doing this here instead than in the middleware allow reactivity on the auth user
2324
watchEffect(async () => {
24-
if (isPendingAuth.value) {
25+
if (isMePending.value) {
2526
return;
2627
}
2728
const shouldRedirectToLogin =
28-
!authStore.isAuthenticated &&
29-
authStore.authUrl &&
30-
route.name !== "auth-login";
29+
!isAuthenticated.value && authUrl.value && route.fullPath !== authUrl.value;
3130
if (shouldRedirectToLogin) {
32-
await navigateTo(authStore.authUrl, { external: true });
31+
return navigateTo(authUrl.value, { external: true });
3332
}
3433
const shouldRedirectToHomepage =
35-
authStore.isAuthenticated && route.name === "auth-login";
34+
isAuthenticated.value && route.fullPath === authUrl.value;
3635
if (shouldRedirectToHomepage) {
37-
await navigateTo("/");
36+
return navigateTo("/");
3837
}
3938
});
4039
</script>

apps/front/src/components/layout/AppHeader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ import { useAuthUser } from "~/store/auth";
1313
1414
const authStore = useAuthUser();
1515
16-
const username = authStore.authUser?.username || "";
16+
const username = authStore.me.email || "";
1717
</script>

apps/front/src/components/user/UserForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</div>
3131
</template>
3232
<script setup lang="ts">
33-
import { User } from "~/types/user";
33+
import { User } from "~/types/User";
3434
3535
defineProps<
3636
Omit<User, "id"> & {

apps/front/src/composables/api/auth/useMe.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

apps/front/src/composables/api/user/useCreateUser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { POST } from "~/constants/http";
2-
import { User } from "~/types/user";
2+
import { User } from "~/types/User";
33
import { Ref } from "vue";
44
import useBasicError from "~/composables/useBasicError";
55

apps/front/src/composables/api/user/useDeleteUser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { User } from "~/types/user";
1+
import { User } from "~/types/User";
22
import { DELETE } from "~/constants/http";
33

44
export default function useDeleteUser() {

apps/front/src/composables/api/user/useGetUser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GET } from "~/constants/http";
2-
import { User } from "~/types/user";
2+
import { User } from "~/types/User";
33
import useAppFetch from "~/composables/useAppFetch";
44

55
export default async function useGetUser(userId: string) {

apps/front/src/composables/api/user/useListUsers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { User } from "~/types/user";
1+
import { User } from "~/types/User";
22
import { GET } from "~/constants/http";
33
import useAppFetch from "~/composables/useAppFetch";
44

apps/front/src/composables/api/user/useUpdateUser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PUT } from "~/constants/http";
2-
import { User, UserId } from "~/types/user";
2+
import { User, UserId } from "~/types/User";
33
import useBasicError from "~/composables/useBasicError";
44

55
type UserInput = Omit<User, "id">;

apps/front/src/composables/useAppFetch.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export default function useAppFetch<T>(
1212
const defaults: UseFetchOptions<T | undefined | unknown> = {
1313
$fetch: $appFetch as $Fetch<unknown, NitroFetchRequest>,
1414
};
15-
1615
// for nice deep defaults, please use unjs/defu
1716
const params = defu(options, defaults);
1817

0 commit comments

Comments
 (0)