Open
Description
Describe the bug
A clear and concise description of what the bug is.
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Amplify, Auth } from 'aws-amplify';
import { Authenticator } from '@aws-amplify/ui-react';
import { environment } from '../../environments/environment';
export const defaultConfig = {
Auth: {
userPoolId: environment.REACT_APP_USER_POOL_ID,
userPoolWebClientId: environment.REACT_APP_USER_POOL_WEB_CLIENT_ID,
region: environment.REACT_APP_AWS_REGION,
mandatorySignIn: false,
// OPTIONAL - Hosted UI configuration
oauth: {
responseType: 'code', // or 'token', note that REFRESH token will only be generated when the responseType is code
},
},
};
/**
* Ath instance of aws-amplify AuthClass
*/
export const authInstance = Auth;
/**
* AmplifyClass instance of aws-amplify
*/
export const amplifyInstance = Amplify;
/* istanbul ignore next */
export class AmplifyService {
public static authToken = '';
public static userInfo:any = null;
/**
*
* @param config
* default value is set using env variables
* ```
* {
* Auth: {
* userPoolId: environment.REACT_APP_USER_POOL_ID,
* userPoolWebClientId: environment.REACT_APP_USER_POOL_WEB_CLIENT_ID,
* region: environment.REACT_APP_AWS_REGION,
* },
* }
* ```
*/
public static configure = (config = defaultConfig) => {
amplifyInstance.configure(config);
};
public static getAuthHeader = async () => {
const data = await authInstance.currentSession();
this.authToken = `Bearer ${data.getAccessToken().getJwtToken()}`;
return this.authToken;
};
public static getUserAccess = async () => {
const data = await authInstance.currentSession();
const userGroups = data.getAccessToken().payload['cognito:groups'];
return {
userAccess: [...userGroups],
};
};
public static getUserInfo = async () => {
if(!this.userInfo) {
const data = await authInstance.currentAuthenticatedUser();
this.userInfo = {
username: data.username,
email: data.attributes.email,
};
}
return this.userInfo;
};
public static signOut = async () => {
await authInstance.signOut({ global: true });
};
}
export { Authenticator };
To Reproduce
Steps to reproduce the behavior:
- use "@aws-amplify/ui-react": "^5.3.1", and "aws-amplify": "^5.3.11",
- upgrade to "@aws-amplify/ui-react": "^6.0.5", "aws-amplify": "^6.0.6",
- and everything breaks
Expected behavior
Why so many breaking changes with these upgrades. It seems to happen every time and takes hours and hours to fix?
Is there a road-map with depreciation warnings so devs / organizations can work efficiently with your software?
Documentation or upgrade paths would be nice as well. Been searching groups for 6 hours on here and .payload['cognito:groups']
accessToken? idToken? every post is ancient across the internet.