feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
14.97k stars 744 forks source link

TypeError: Cannot read properties of undefined (reading 'sub') #3266

Closed MarcGodard closed 9 months ago

MarcGodard commented 10 months ago

Steps to reproduce

error: TypeError: Cannot read properties of undefined (reading 'sub')
    at GoogleStrategy.getEntityQuery (/home/marcgodard/Documents/Github/gozamm-api/node_modules/@feathersjs/authentication-oauth/lib/strategy.js:29:41)
    at GoogleStrategy.findEntity (/home/marcgodard/Documents/Github/gozamm-api/node_modules/@feathersjs/authentication-oauth/lib/strategy.js:79:34)
    at GoogleStrategy.authenticate (/home/marcgodard/Documents/Github/gozamm-api/node_modules/@feathersjs/authentication-oauth/lib/strategy.js:118:44)

Expected behavior

No error and user created

Actual behavior

Above Error

System configuration

Brand new feathers 5.0.8 project (javascript, npm, json schemas)

Module versions (especially the part that's not working): 5.0.8

NodeJS version: v16

Operating System: linux

MarcGodard commented 10 months ago

In Strategy.js Changing this:

    async getEntityQuery(profile, _params) {
        console.log(profile)
        return {
            [`${this.name}Id`]: profile.sub || profile.id
        };
    }
    async getEntityData(profile, _existingEntity, _params) {
        console.log(profile)
        return {
            [`${this.name}Id`]: profile.sub || profile.id
        };
    }

To this (in my node_module files):

    async getEntityQuery(profile, _params) {
        console.log(profile)
        return {
            [`${this.name}Id`]: profile?.sub ?? String(profile.id)
        };
    }
    async getEntityData(profile, _existingEntity, _params) {
        console.log(profile)
        return {
            [`${this.name}Id`]: profile?.sub ?? String(profile.id)
        };
    }

Made it work for both Google and Github.

JonasTheGamer commented 10 months ago

Hm, after applying your fix I'm now getting this error:

info: Feathers app listening on http://FlexibeleJonas2:3030
undefined
error: TypeError: Cannot read properties of undefined (reading 'id')
    at GitHubStrategy.getEntityQuery (C:\1_LOKALE_PROJECTEN\BloxTech\ResearchAndDevelopment\Feathersjs\feathers-chat\node_modules\@feathersjs\authentication-oauth\lib\strategy.js:30:64)
    at GitHubStrategy.findEntity (C:\1_LOKALE_PROJECTEN\BloxTech\ResearchAndDevelopment\Feathersjs\feathers-chat\node_modules\@feathersjs\authentication-oauth\lib\strategy.js:81:34)
    at GitHubStrategy.authenticate (C:\1_LOKALE_PROJECTEN\BloxTech\ResearchAndDevelopment\Feathersjs\feathers-chat\node_modules\@feathersjs\authentication-oauth\lib\strategy.js:120:44)
MarcGodard commented 9 months ago

@JonasTheGamer Not sure why you are getting this, other than you are not requesting that information? Is this with google or github? I didn't test other services, as I thought this was close enough to the original not to impact others.

gypsicoder commented 9 months ago

@MarcGodard I had get the same error. I think you didn't started the Database server. Please start the database server and then try again. I think the error description is wrong.

MarcGodard commented 9 months ago

@gypsicoder I don't think the database had anything to do with it.

daffl commented 9 months ago

It looks like it is a bug, there are more details reported in https://github.com/feathersjs/feathers/issues/3275 - basically it seems like an error happened (which is why there isn't a profile) but went through the process normally. Needs some more investigation but should be fixed in the next release.

daffl commented 9 months ago

This should be fixed via #3284 in v5.0.9 and propagate the error that likely happened here (instead of just returning an undefined profile).

chrisbag commented 3 months ago

I keep having this issue on v5 (no problem on v4) and I am not sure if it is because of my config or still a bug from feathers oauth. Profile data is empty and the authentication method does not return the google token while no oauth error is shown