Skip to content

Commit

Permalink
Merge pull request #5 from fumeapp/simplify-auth-utils
Browse files Browse the repository at this point in the history
♻️ simplify our auth utils config
  • Loading branch information
acidjazz authored Jan 29, 2025
2 parents 9a910b7 + 558edf2 commit 8ce1b1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export interface ModuleOptions {
apiKey: string
apiDomain: string
verbose: boolean
userFromAuthUtils: boolean
authUtilsUserFields: string[]
authUtils: boolean
authUtilsFields: string[]
}

declare module 'nuxt/schema' {
Expand Down Expand Up @@ -37,13 +37,13 @@ declare module 'nuxt/schema' {
* @default false
*/

userFromAuthUtils?: boolean
authUtils?: boolean
/**
* Customize the fields that are plucked from the user supplied from nuxt-auth-utils
*
* @default ['id', 'email', 'name', 'avatar']
*/
authUtilsUserFields?: string[]
authUtilsFields?: string[]
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/runtime/care.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ interface ErrorMeta {
export const careConfigDefaults = {
apiDomain: 'https://fume.care',
verbose: false,
userFromAuthUtils: false,
authUtilsUserFields: ['id', 'email', 'name', 'avatar'],
authUtils: false,
authUtilsFields: ['id', 'email', 'name', 'avatar'],
}

const mergeConfig = (config: Config) => {
Expand Down Expand Up @@ -66,15 +66,15 @@ const getMeta = async (config: Config, event?: H3Event) => {
const meta: ErrorMeta = { user: undefined, meta: undefined }

// if we are incorporating nuxt-auth-utils in app/
if (config.userFromAuthUtils && !event && typeof useUserSession === 'function') {
if (config.authUtils && !event && typeof useUserSession === 'function') {
const { user } = useUserSession()
meta.user = userFromFields(user.value, config.authUtilsUserFields)
meta.user = userFromFields(user.value, config.authUtilsFields)
}

// if we are incorporating nuxt-auth-utils in server/
if (config.userFromAuthUtils && event && typeof getUserSession === 'function') {
if (config.authUtils && event && typeof getUserSession === 'function') {
const { user } = await getUserSession(event)
meta.user = userFromFields(user, config.authUtilsUserFields)
meta.user = userFromFields(user, config.authUtilsFields)
}
if (config.verbose) log.info('[fume.care] stored meta being sent:', JSON.stringify(meta))
return meta
Expand Down

0 comments on commit 8ce1b1f

Please sign in to comment.