Skip to content

Commit

Permalink
refactor: Linter fix
Browse files Browse the repository at this point in the history
  • Loading branch information
riceball-tw committed Jan 9, 2025
1 parent 6b3e883 commit 6a1c481
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 41 deletions.
2 changes: 1 addition & 1 deletion components/note/NoteListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<template>
<li>
<button :disabled="isActive" :class="isActive ? 'bg-primary' : 'hover:bg-primary/60'" class="p-4 flex w-full gap-2 flex-col items-start text-left" type="button" @click="() => emit('change-current-note-id', noteId)">
<div class="line-clamp-1" v-if="title">{{ title }}</div>
<div v-if="title" class="line-clamp-1">{{ title }}</div>
<div v-else>
Untitled
</div>
Expand Down
2 changes: 0 additions & 2 deletions composables/useSignUp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { AsyncDataRequestStatus } from "#app";

export async function useSignUp(body) {
const { status: signUpStatus } = await useFetch('/api/user', {
method: 'POST',
Expand Down
4 changes: 2 additions & 2 deletions middleware/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default defineNuxtRouteMiddleware(async (event) => {
export default defineNuxtRouteMiddleware(async () => {
if (import.meta.client) return

const { $verifyJwtToken } = useNuxtApp()
Expand All @@ -9,7 +9,7 @@ export default defineNuxtRouteMiddleware(async (event) => {
}
try {
await $verifyJwtToken(jwtCookie.value, process.env.JWT_SECRET as string)
} catch(err) {
} catch {
return navigateTo('/signup')
}
})
22 changes: 11 additions & 11 deletions pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { useDebounceFn } from '@vueuse/core';
import { Plus, Trash2, CircleUser, Home, Menu, ScrollText, Search, Loader2 } from 'lucide-vue-next'
import { Plus, Trash2, CircleUser, Menu, ScrollText, Loader2 } from 'lucide-vue-next'
import type { AsyncDataRequestStatus } from "#app";
definePageMeta({
Expand Down Expand Up @@ -166,11 +166,11 @@
<ScrollText class="h-6 w-6" />
<span class="">MyNote</span>
</a>
<Button v-if="createNoteStatus === 'pending'" @click="handleCreateNote" variant="outline" size="icon" class="ml-auto h-8 w-8">
<Button v-if="createNoteStatus === 'pending'" variant="outline" size="icon" class="ml-auto h-8 w-8" @click="handleCreateNote">
<Loader2 class="w-4 h-4 animate-spin" />
<span class="sr-only" aria-live="polite">Creating Note</span>
</Button>
<Button v-else @click="handleCreateNote" variant="outline" size="icon" class="ml-auto h-8 w-8">
<Button v-else variant="outline" size="icon" class="ml-auto h-8 w-8" @click="handleCreateNote">
<Plus class="h-4 w-4" />
<span class="sr-only">Create Note</span>
</Button>
Expand All @@ -184,7 +184,7 @@
</div>
<ol>
<template v-for="note in notesGroupByCategory['today']" :key="note.id">
<NoteListItem :noteId="note.id" :isActive="note.id === currentNoteId" :title="note.text ?? ''" subTitle="Today" @change-current-note-id="(id) => handleChangeCurrentNoteId(id)"></NoteListItem>
<NoteListItem :note-id="note.id" :is-active="note.id === currentNoteId" :title="note.text ?? ''" sub-title="Today" @change-current-note-id="(id) => handleChangeCurrentNoteId(id)"/>
</template>
</ol>

Expand All @@ -195,7 +195,7 @@
</div>
<ol>
<template v-for="note in notesGroupByCategory['yesterday']" :key="note.id">
<NoteListItem :noteId="note.id" :isActive="note.id === currentNoteId" :title="note.text ?? ''" subTitle="Yesterday" @change-current-note-id="(id) => handleChangeCurrentNoteId(id)"></NoteListItem>
<NoteListItem :note-id="note.id" :is-active="note.id === currentNoteId" :title="note.text ?? ''" sub-title="Yesterday" @change-current-note-id="(id) => handleChangeCurrentNoteId(id)"/>
</template>
</ol>
<div class="flex justify-between px-4 py-2 text-sm font-semibold">
Expand All @@ -204,7 +204,7 @@
</div>
<ol>
<template v-for="note in notesGroupByCategory['earlier']" :key="note.id">
<NoteListItem :noteId="note.id" :isActive="note.id === currentNoteId" :title="note.text ?? ''" :subTitle="new Date(note.updatedAt).toLocaleDateString()" @change-current-note-id="(id) => handleChangeCurrentNoteId(id)"></NoteListItem>
<NoteListItem :note-id="note.id" :is-active="note.id === currentNoteId" :title="note.text ?? ''" :sub-title="new Date(note.updatedAt).toLocaleDateString()" @change-current-note-id="(id) => handleChangeCurrentNoteId(id)"/>
</template>
</ol>
</div>
Expand Down Expand Up @@ -241,7 +241,7 @@
</div>
<ol>
<template v-for="note in notesGroupByCategory['today']" :key="note.id">
<NoteListItem :noteId="note.id" :isActive="note.id === currentNoteId" :title="note.text ?? ''" subTitle="Today" @change-current-note-id="(id) => handleChangeCurrentNoteId(id)"></NoteListItem>
<NoteListItem :note-id="note.id" :is-active="note.id === currentNoteId" :title="note.text ?? ''" sub-title="Today" @change-current-note-id="(id) => handleChangeCurrentNoteId(id)"/>
</template>
</ol>

Expand All @@ -251,7 +251,7 @@
</div>
<ol>
<template v-for="note in notesGroupByCategory['yesterday']" :key="note.id">
<NoteListItem :noteId="note.id" :isActive="note.id === currentNoteId" :title="note.text ?? ''" subTitle="Yesterday" @change-current-note-id="(id) => handleChangeCurrentNoteId(id)"></NoteListItem>
<NoteListItem :note-id="note.id" :is-active="note.id === currentNoteId" :title="note.text ?? ''" sub-title="Yesterday" @change-current-note-id="(id) => handleChangeCurrentNoteId(id)"/>
</template>
</ol>

Expand All @@ -261,7 +261,7 @@
</div>
<ol>
<template v-for="note in notesGroupByCategory['earlier']" :key="note.id">
<NoteListItem :noteId="note.id" :isActive="note.id === currentNoteId" :title="note.text ?? ''" :subTitle="new Date(note.updatedAt).toLocaleDateString()" @change-current-note-id="(id) => handleChangeCurrentNoteId(id)"></NoteListItem>
<NoteListItem :note-id="note.id" :is-active="note.id === currentNoteId" :title="note.text ?? ''" :sub-title="new Date(note.updatedAt).toLocaleDateString()" @change-current-note-id="(id) => handleChangeCurrentNoteId(id)"/>
</template>
</ol>

Expand Down Expand Up @@ -313,15 +313,15 @@
<time class="mb-8 inline-block">
Last Updated: {{ new Date(currentNote.updatedAt).toLocaleDateString() }}
</time>
<textarea ref="noteTextarea" v-model="updatedNoteText" @input="handleDebouncedUpdateNote" class="w-full h-full focus:outline-none resize-none">{{ currentNote.text }}</textarea>
<textarea ref="noteTextarea" v-model="updatedNoteText" class="w-full h-full focus:outline-none resize-none" @input="handleDebouncedUpdateNote" />
</div>
</div>

<Button v-if="deleteNoteStatus === 'pending'" :disabled="true" variant="destructive" size="icon" class="w-full">
<Loader2 class="w-4 h-4 animate-spin" />
<span aria-live="polite">Deleting Note</span>
</Button>
<Button v-else :disabled="!currentNoteId" @click="handleDeleteNote" variant="outline" size="icon" class="w-full">
<Button v-else :disabled="!currentNoteId" variant="outline" size="icon" class="w-full" @click="handleDeleteNote">
<Trash2 class="h-4 w-4" />
Delete Note
</Button>
Expand Down
2 changes: 1 addition & 1 deletion plugins/jwt.server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PublicKeyInput, JsonWebKeyInput } from 'crypto'
import jwt from 'jsonwebtoken'

export default defineNuxtPlugin((nuxtApp) => {
export default defineNuxtPlugin(() => {
return {
provide: {
verifyJwtToken: (token: string, secret: jwt.Secret | PublicKeyInput | Buffer<ArrayBufferLike> | JsonWebKeyInput, options?: jwt.VerifyOptions & { complete: true }) => {
Expand Down
34 changes: 15 additions & 19 deletions server/api/notes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,24 @@ import jwt from 'jsonwebtoken'
import { eq } from 'drizzle-orm';

export default defineEventHandler(async (event) => {
try {
const cookies = parseCookies(event)
const userJwtToken = cookies.userJwtToken
const cookies = parseCookies(event)
const userJwtToken = cookies.userJwtToken

if (!userJwtToken) {
throw createError({
statusCode: 401,
message: "Not authorized to access notes"
})
}

const decodedToken = await jwt.verify(userJwtToken, process.env.JWT_SECRET as string) as { id: number }
if (!userJwtToken) {
throw createError({
statusCode: 401,
message: "Not authorized to access notes"
})
}

const decodedToken = await jwt.verify(userJwtToken, process.env.JWT_SECRET as string) as { id: number }

const targetUser = await db
.select()
.from(notesTable)
.where(eq(notesTable.userId, decodedToken.id))


return targetUser
} catch(err) {
const targetUser = await db
.select()
.from(notesTable)
.where(eq(notesTable.userId, decodedToken.id))


}
return targetUser
})
5 changes: 2 additions & 3 deletions server/api/user/signin.post.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { db } from '@/src/index'
import { usersTable } from '@/src/db/schema';
import { usersTable, usersInsertRequestSchema } from '@/src/db/schema';
import bcrypt from 'bcryptjs'
import { usersInsertRequestSchema } from '@/src/db/schema';
import { readValidatedBody } from "h3";
import { fromError } from 'zod-validation-error';
import jwt from 'jsonwebtoken'
Expand Down Expand Up @@ -32,7 +31,7 @@ export default defineEventHandler(async (event) => {
const userJwtToken = jwt.sign({ id: targetUser.id }, process.env.JWT_SECRET as string)
setCookie(event, 'userJwtToken', userJwtToken)
setResponseStatus(event, 204)
} catch(err) {
} catch {
throw createError({
statusCode: 401,
message: "Username or Password is invalid."
Expand Down
3 changes: 1 addition & 2 deletions server/api/user/signup.post.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { db } from '@/src/index'
import { usersTable } from '@/src/db/schema';
import { usersTable, usersInsertRequestSchema } from '@/src/db/schema';
import bcrypt from 'bcryptjs'
import type { QueryError } from 'mysql2'
import { usersInsertRequestSchema } from '@/src/db/schema';
import { readValidatedBody } from "h3";
import { fromError } from 'zod-validation-error';
import jwt from 'jsonwebtoken'
Expand Down

0 comments on commit 6a1c481

Please sign in to comment.