amplify-js: Not able to get refreshToken in Amplify 6
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
React
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
None
Environment information
System:
OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
CPU: (16) x64 13th Gen Intel(R) Core(TM) i5-13500H
Memory: 6.81 GB / 11.68 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 18.20.4 - ~/.nvm/versions/node/v18.20.4/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v18.20.4/bin/yarn
npm: 10.7.0 - ~/.nvm/versions/node/v18.20.4/bin/npm
pnpm: 9.15.4 - ~/.nvm/versions/node/v18.20.4/bin/pnpm
npmPackages:
@asseinfo/react-kanban: ^2.1.0 => 2.2.0
@handsontable/react: ^14.3.0 => 14.6.2
@material-ui/lab: ^4.0.0-alpha.58 => 4.0.0-alpha.61
@material-ui/pickers: ^3.3.10 => 3.3.11
@material-ui/utils: ^4.11.3 => 4.11.3
@types/lodash: 4.17.14 => 4.17.14
@types/react: ~17.0.83 => 17.0.83
@types/react-dom: ~17.0.26 => 17.0.26
@typescript-eslint/eslint-plugin: 8.21.0 => 8.21.0
@typescript-eslint/parser: 8.21.0 => 8.21.0
@vitejs/plugin-react: 4.2.1 => 4.2.1
axios: ^0.21.4 => 0.21.4
clsx: ^1.1.1 => 1.2.1
eslint: ^8.9.0 => 8.55.0
eslint-plugin-react: ^7.28.0 => 7.33.2
eslint-plugin-react-hooks: ^4.3.0 => 4.6.0
handsontable: ^14.2.0 => 14.6.2
prettier: ^2.7.1 => 2.8.8
react: ^17.0.2 => 17.0.2
react-calendly: ^2.2.2 => 2.2.3
react-canvas-draw: ^1.2.1 => 1.2.1
react-dom: ^17.0.2 => 17.0.2
react-redux: ^7.2.4 => 7.2.9
typescript: 5.7.3 => 5.7.3
uuid: ^8.3.2 => 8.3.2
vite: 5.0.8 => 5.0.8
npmGlobalPackages:
@rollup/rollup-linux-x64-gnu: 4.25.0
aws-amplify: 6.13.4
corepack: 0.28.0
eslint: 9.20.1
lighthouse: 12.3.0
npm: 10.7.0
pnpm: 9.15.4
wscat: 6.0.1
yarn: 1.22.22
Describe the bug
We have moved from Amplify v4 to v6 for one of our projects. We are using fetchAuthSession here which returns the accessToken but not the refreshToken.
Normally this won’t be an issue but there’s another electron js project which leverages the first project. We are using the amazon-cognito-identity-js package on electron BE, and it expects the refresh token to be passed to it.
Before when we were using amplify v4, we sign in the user and get the refresh token using Auth.currentSession().getRefreshToken().getToken() which is then passed to electron BE. Can this be done for Amplify v6 also?
Expected behavior
fetchAuthSession should also return the refresh token in addition to access token
Reproduction steps
- Sign in the user
- Use
fetchAuthSession()to get the tokens. refreshToken is not present.
Code Snippet
// Put your code below this line.
Log output
// Put your logs below this line
aws-exports.js
No response
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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (9 by maintainers)
Are the API calls Amplify API calls? If a token is required for making API calls, it should be that only access token is required in most cases, the refresh token is only used for refreshing expired access token. You may consider passing the access token from the renderer to the backend instead. Access may expire token, since you are calling
fetchAuthSession()already, the token refresh should be handled automatically.@pranjalBild Hope the above answer helped you. If there is no further clarification we will be closing this issue.
@pranjalBild
forceRefreshis different configuration all together. That is used to refresh on before making an API request irrespective of expiration.fetchAuthSessionunder the hood automatically takes care of refreshing the token if it expires.If you asking about this in context of the below implementation, you only need the following block if you want to force refresh the token irrespective of expiration. You can remove it otherwise
Hi @pranjalBild in Amplify JS v6,
fetchAuthSessionelaborately omits refresh token from the returning result as it’s the most important token and expected to be used only by Amplify JS internally.Could you give us more details about the use cases where you expect to use the refresh token directly?