Skip to content

Commit

Permalink
🐛 fix for calling the right session function
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Jan 27, 2025
1 parent 687ef74 commit f91e03c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ModuleOptions {
}

declare module 'nuxt/schema' {
interface PubilcRuntimeConfig {
interface PublicRuntimeConfig {
care: {
/**
* fume.care API Key
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/care.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export enum CareHookType {

const userFromFields = (user: Record<string, unknown>, fields: string[]) => {
if (!user || !fields?.length) return undefined

const filtered = Object.fromEntries(
fields
.filter(key => user[key] !== undefined)
Expand All @@ -65,7 +64,7 @@ const userFromFields = (user: Record<string, unknown>, fields: string[]) => {

const getMeta = async (config: Config, event?: H3Event) => {
const meta: ErrorMeta = { user: undefined, meta: undefined }
if (config.userFromAuthUtils && typeof useUserSession === 'function') {
if (config.userFromAuthUtils && !event && typeof useUserSession === 'function') {
const { user } = useUserSession()
meta.user = userFromFields(user.value, config.authUtilsUserFields)
}
Expand All @@ -74,7 +73,7 @@ const getMeta = async (config: Config, event?: H3Event) => {
const { user } = await getUserSession(event)
meta.user = userFromFields(user, config.authUtilsUserFields)
}
if (config.verbose) log.info('[fume.care] Meta:', meta)
if (config.verbose) log.info('[fume.care] meta:', JSON.stringify(meta))
return meta
}

Expand Down Expand Up @@ -124,14 +123,15 @@ export const careReport = async (type: CareHookType, err: unknown, unmerged: Con
if (config.verbose) {
log.info(`[fume.care] Error in ${type} going to ${url}`, payload)
}
const meta = await getMeta(config, event)
const response = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
apiKey: config.apiKey,
environment: 'production',
payload: JSON.stringify(payload),
meta: JSON.stringify(await getMeta(config, event)),
meta: JSON.stringify(meta),
}),
})
const data = await response.json()
Expand Down

0 comments on commit f91e03c

Please sign in to comment.