atinux / nuxt-auth-utils

Add Authentication to Nuxt applications with secured & sealed cookies sessions.
MIT License
976 stars 91 forks source link

feat: add opts to requireUserSession for error message and status code customization #76

Closed dethdkn closed 7 months ago

dethdkn commented 7 months ago

Hello, This PR introduces the ability to customize the status code and error message in the requireUserSession method. This feature is particularly useful for applications that are not in English.

I use the returned error message on my apps, and I wish I could translate the Unauthorized message to my language

atinux commented 7 months ago

Thank you for the PR @dethdkn

Don't you want to translate on the application side instead of the API @dethdkn ?

dethdkn commented 7 months ago

Hey @Atinux I translate both 😅, Most of my $fetch are like this

const res = await $fetch('/do-something', { method: 'post', body: body.data })
    .catch((err) => { toast.add({ title: err.data.message, icon: 'i-heroicons-exclamation-triangle', color: 'red' }) })

I get the returned api message and show it as a toast I'm not sure if it's the best way to work with $fetch catch, but, it has been working here since my api have multiple throws.

dethdkn commented 7 months ago

Also sorry for the inconsistent spacing on the opts type, I thought eslint would fix that

atinux commented 7 months ago

Happy to fix the conflicts with the new eslint rules? see #79

dethdkn commented 7 months ago

Fixed @Atinux 🫡