aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.4k stars 2.11k forks source link

No current user after federated sign in #11245

Closed mtergel closed 1 year ago

mtergel commented 1 year ago

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

``` # Put output below this line System: OS: macOS 13.3.1 CPU: (8) arm64 Apple M1 Memory: 4.78 GB / 16.00 GB Shell: 3.6.1 - /opt/homebrew/bin/fish Binaries: Node: 19.8.1 - /opt/homebrew/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 9.5.1 - /opt/homebrew/bin/npm Browsers: Firefox Developer Edition: 113.0 Safari: 16.4 npmPackages: @ampproject/toolbox-optimizer: undefined () @babel/core: undefined () @babel/runtime: 7.15.4 @edge-runtime/primitives: 1.1.0-beta.31 @hapi/accept: undefined () @napi-rs/triples: undefined () @next/bundle-analyzer: ^12.3.1 => 12.3.1 @next/react-dev-overlay: undefined () @radix-ui/react-accordion: ^1.0.1 => 1.0.1 @radix-ui/react-alert-dialog: ^1.0.2 => 1.0.2 @radix-ui/react-avatar: ^1.0.1 => 1.0.1 @radix-ui/react-collapsible: ^1.0.1 => 1.0.1 @radix-ui/react-dialog: ^1.0.2 => 1.0.2 @radix-ui/react-hover-card: ^1.0.2 => 1.0.2 @radix-ui/react-navigation-menu: ^1.1.1 => 1.1.1 @radix-ui/react-portal: ^1.0.1 => 1.0.1 @radix-ui/react-switch: ^1.0.1 => 1.0.1 @radix-ui/react-tabs: ^1.0.1 => 1.0.1 @segment/ajv-human-errors: undefined () @sentry/react: ^7.21.0 => 7.21.0 @sentry/tracing: ^7.21.0 => 7.21.0 @tailwindcss/forms: ^0.5.3 => 0.5.3 @tailwindcss/line-clamp: ^0.4.2 => 0.4.2 @tailwindcss/typography: ^0.5.8 => 0.5.8 @types/debounce-promise: ^3.1.5 => 3.1.5 @types/gtag.js: ^0.0.12 => 0.0.12 @types/lodash: ^4.14.186 => 4.14.186 @types/node: 18.11.8 => 18.11.8 (16.11.58) @types/nprogress: ^0.2.0 => 0.2.0 @types/react: 18.0.21 => 18.0.21 (18.0.18) @types/react-dom: 18.0.8 => 18.0.8 @types/react-inner-image-zoom: ^3.0.0 => 3.0.0 @types/react-pdf: ^6.2.0 => 6.2.0 @types/sanitize-html: ^2.6.2 => 2.6.2 @vercel/nft: undefined () acorn: undefined () amphtml-validator: undefined () arg: undefined () assert: undefined () async-retry: undefined () async-sema: undefined () autoprefixer: ^10.4.13 => 10.4.13 aws-amplify: ^4.3.42 => 4.3.42 aws-appsync: ^4.1.9 => 4.1.9 babel-packages: undefined () browserify-zlib: undefined () browserslist: undefined () buffer: undefined () bytes: undefined () chalk: undefined () ci-info: undefined () cli-select: undefined () clsx: ^1.2.1 => 1.2.1 comment-json: undefined () compression: undefined () conf: undefined () constants-browserify: undefined () content-disposition: undefined () content-type: undefined () cookie: undefined () cookies-next: ^2.1.1 => 2.1.1 cross-spawn: undefined () crypto-browserify: undefined () cssnano-simple: undefined () dayjs: ^1.11.6 => 1.11.6 debounce-promise: ^3.1.2 => 3.1.2 debug: undefined () devalue: undefined () domain-browser: undefined () downshift: ^7.0.4 => 7.0.4 edge-runtime: undefined () epubjs: ^0.3.93 => 0.3.93 eslint: 8.26.0 => 8.26.0 eslint-config-next: 12.3.1 => 12.3.1 events: undefined () find-cache-dir: undefined () find-up: undefined () fresh: undefined () fuse.js: ^6.6.2 => 6.6.2 get-orientation: undefined () glob: undefined () graphql-tag: ^2.12.6 => 2.12.6 gzip-size: undefined () html-react-parser: ^3.0.4 => 3.0.4 http-proxy: undefined () https-browserify: undefined () icss-utils: undefined () ignore-loader: undefined () image-size: undefined () is-animated: undefined () is-docker: undefined () is-wsl: undefined () jest-worker: undefined () json5: undefined () jsonwebtoken: undefined () jwt-decode: ^3.1.2 => 3.1.2 loader-utils: undefined () lodash.curry: undefined () loglevel: ^1.8.1 => 1.8.1 lru-cache: undefined () micromatch: undefined () mini-css-extract-plugin: undefined () nanoid: ^4.0.0 => undefined (4.0.0, , 3.3.4) native-url: undefined () neo-async: undefined () next: 12.3.1 => 12.3.1 next-seo: ^5.11.1 => 5.11.1 next-sitemap: ^3.1.29 => 3.1.29 next-themes: ^0.2.1 => 0.2.1 next-useragent: ^2.8.0 => 2.8.0 node-fetch: undefined () node-html-parser: undefined () nprogress: ^0.2.0 => 0.2.0 ora: undefined () os-browserify: undefined () p-limit: undefined () path-browserify: undefined () postcss: ^8.4.19 => 8.4.19 (8.4.14, 8.4.18, 8.4.16) postcss-flexbugs-fixes: undefined () postcss-modules-extract-imports: undefined () postcss-modules-local-by-default: undefined () postcss-modules-scope: undefined () postcss-modules-values: undefined () postcss-preset-env: undefined () postcss-safe-parser: undefined () postcss-scss: undefined () postcss-value-parser: undefined () process: undefined () punycode: undefined () qrcode.react: ^3.1.0 => 3.1.0 querystring-es3: undefined () raw-body: undefined () react: 18.2.0 => 18.2.0 react-confetti: ^6.1.0 => 6.1.0 react-dom: 18.2.0 => 18.2.0 react-hook-form: ^7.40.0 => 7.40.0 react-icons: ^4.7.1 => 4.7.1 react-inner-image-zoom: ^3.0.2 => 3.0.2 react-intersection-observer: ^9.4.1 => 9.4.1 react-is: 17.0.2 react-number-format: ^5.1.2 => 5.1.2 react-pdf: ^6.2.0 => 6.2.0 react-pin-input: ^1.3.0 => 1.3.0 react-refresh: 0.12.0 react-resize-detector: ^7.1.2 => 7.1.2 react-server-dom-webpack: undefined () react-toastify: ^9.1.1 => 9.1.1 regenerator-runtime: 0.13.4 sanitize-html: ^2.7.3 => 2.7.3 sass: ^1.56.1 => 1.56.1 sass-loader: undefined () schema-utils: undefined () semver: undefined () send: undefined () setimmediate: undefined () sharp: ^0.31.2 => 0.31.2 source-map: undefined () stream-browserify: undefined () stream-http: undefined () string-hash: undefined () string_decoder: undefined () strip-ansi: undefined () swiper: ^8.4.5 => 8.4.5 swiper_angular: 0.0.1 swr: ^1.3.0 => 1.3.0 swr-immutable: 0.0.1 swr-infinite: 0.0.1 tailwindcss: ^3.2.4 => 3.2.4 tar: undefined () terser: undefined () text-table: undefined () timers-browserify: undefined () tty-browserify: undefined () typescript: 4.9.3 => 4.9.3 ua-parser-js: undefined () unistore: undefined () util: undefined () vm-browserify: undefined () watchpack: undefined () web-vitals: undefined () webpack: undefined () webpack-sources: undefined () ws: undefined () zustand: ^4.1.5 => 4.1.5 npmGlobalPackages: npm: 9.5.1 ```

Describe the bug

I'm following this code sample in here

The code is working, I'm getting the results from the federatedSignIn but, when I call currentAuthenticatedUser() it errors out with no current user.

But when I log the payload in Hub, signIn event there data

email: "email here..."
​​​id: "ap-southeast-1:a82a9f2d-adba-4ed1-85df-8f9c819130e6"
​​​name: "name here..."
​​token: "eyJhbGciOiJSUzI1N... more here"
​​​

Or is this the intended behavior, sorry I was just wanted to use an popup for OAuth logins instead of redirects.

Expected behavior

Logged in with Cognito user after federatedSignIn.

Reproduction steps

https://docs.amplify.aws/lib/auth/advanced/q/platform/js/#google-sign-in-react

Code Snippet

Log output

``` // Put your logs below this line ```

aws-exports.js

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

nadetastic commented 1 year ago

Hi @mtergel thank you for opening this issue.

Please note that I redacted the aws_appsync_apiKey from your comment, and recommend invalidating it as it can allow anyone to access your API directly.

Regarding the Federated Sign issue can you confirm the following:

mtergel commented 1 year ago
nadetastic commented 1 year ago

@mtergel we've removed the previous comment and I have re-opened the issue

As for the mention on advanced flow, I assume you are referring to this? - https://docs.amplify.aws/lib/auth/advanced/q/platform/js/#google-sign-in-react

nadetastic commented 1 year ago

@mtergel FYI, I just tried this out with "aws-amplify": "4.3.42" and I am able to get the user with Auth.currentAuthenticatedUser after Auth.federatedSignIn() as shown in the documentation you linked.

Could you share you package.json?

mtergel commented 1 year ago

yeah I missed a note in the documentation.

Note that this isn't from a Cognito User Pool so the user you get after calling this method is not a Cognito User.

So I think I've been using it the wrong way, Sorry. Umm, any idea how to get an Social Login with popup instead of redirecting with aws-amplify cognito.