Skip to content

Commit

Permalink
fix(auth): fix no session bug
Browse files Browse the repository at this point in the history
  • Loading branch information
amandesai01 committed Sep 10, 2024
1 parent 5839dfa commit 8dac2bb
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/components/admin/MemberCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const onRemove = () => {
title="Remove Member?"
confirmLabel="Remove"
content="Member's access will be immediatly disabled. No actions performed by member will be reverted."
v-if="profile.id != member.id"
v-if="profile?.id != member.id"
>
<template #input="{ open }">
<InputButton variant="destructive" size="icon" @click="open">
Expand Down
4 changes: 2 additions & 2 deletions app/composables/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function useAuth() {
const session = useSessionState();
const isSignedIn = computed(() => !!session.value.profile);
const profile = computed(() => session.value.profile);
const isSignedIn = computed(() => !!session.value?.profile);
const profile = computed(() => session.value?.profile);

return {
session,
Expand Down
2 changes: 1 addition & 1 deletion app/composables/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type CareerSiteConfig, type SEOConfig } from '~~/shared/schemas/setting
import type { Session } from '~~/shared/types/profile-types';

export function useSessionState() {
return useState<Session>('oauth_session');
return useState<Session | null>('oauth_session');
}

export function useRemoteAssetBaseState() {
Expand Down
2 changes: 1 addition & 1 deletion app/middleware/admin-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineNuxtRouteMiddleware(async (to) => {
return redirectToLogin(to.fullPath);
}

if (!profile.value.isAdmin) {
if (!profile.value?.isAdmin) {
return navigateTo('/');
}
});
2 changes: 1 addition & 1 deletion app/pages/admin/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { profile } = useAuth();
<template>
<div class="w-full max-w-9xl mx-auto">
<section class="sticky top-0 bg-white p-4 border-b border-zinc-200">
<div class="text-xl font-bold text-zinc-900 font-noto">👋🏽 Hello, {{ profile.firstName }}</div>
<div class="text-xl font-bold text-zinc-900 font-noto">👋🏽 Hello, {{ profile?.firstName }}</div>
<div class="text-sm text-zinc-500">Track your hiring activities. You are almost there!</div>
<div class="flex items-center mt-4">
<InputButton as="NuxtLink" variant="secondary" to="/admin/postings/new">
Expand Down
3 changes: 2 additions & 1 deletion server/api/userinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export default defineEventHandler(async (event) => {

return session;
} catch (e) {
if (IS_DEV) {
// @ts-expect-error
if (e.statusCode !== 401) {
console.error(e);
}
throw e;
Expand Down

0 comments on commit 8dac2bb

Please sign in to comment.