Skip to content

Commit

Permalink
ook
Browse files Browse the repository at this point in the history
  • Loading branch information
yunusefendi52 committed Mar 31, 2024
1 parent cdf3be9 commit d4053a7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { createCommonJS } from 'mlly'
const { __dirname } = createCommonJS(import.meta.url)

export default defineNuxtConfig({
runtimeConfig: {
JWT_KEY: '',
},
nitro: {
preset: 'bun',
experimental: {
Expand Down
5 changes: 2 additions & 3 deletions server/api/auth/signin.post.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import jsonwebtoken from 'jsonwebtoken'

const secret: string = process.env.JWT_SECRET!

export default defineEventHandler(async (event) => {
const { JWT_KEY } = useRuntimeConfig(event)
const token = jsonwebtoken.sign({
name: 'Yunus',
userId: 1,
}, secret, {})
}, JWT_KEY, {})
setCookie(event, 'app-auth', token)
return {
ok: true,
Expand Down
4 changes: 2 additions & 2 deletions server/middleware/auth-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ declare module 'h3' {
}
}

const secret: string = process.env.JWT_SECRET!

export default defineEventHandler((event) => {
const appAuth = getCookie(event, 'app-auth')
if (appAuth) {
const verifiedData = jsonwebtoken.verify(appAuth, secret)
const { JWT_KEY } = useRuntimeConfig(event)
const verifiedData = jsonwebtoken.verify(appAuth, JWT_KEY)
// if (!verifiedData) {
// deleteCookie(event, 'app-auth')
// }
Expand Down

0 comments on commit d4053a7

Please sign in to comment.