Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MarcGodard opened this issue Aug 26, 2023 · 8 comments · Fixed by #3284
Closed

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

MarcGodard opened this issue Aug 26, 2023 · 8 comments · Fixed by #3284

Comments

@MarcGodard
Copy link
Contributor

Steps to reproduce

  • Create new project (then add authentication as per docs), setup google or github (probably others too) for oauth
  • visit correct /oauth/google folder
  • authorize the app
  • app redirects
  • get the following error:
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
Copy link
Contributor Author

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
Copy link

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
Copy link
Contributor Author

@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
Copy link

@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
Copy link
Contributor Author

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

@daffl
Copy link
Member

daffl commented Sep 22, 2023

It looks like it is a bug, there are more details reported in #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
Copy link
Member

daffl commented Sep 27, 2023

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
Copy link

chrisbag commented Apr 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants