Adding assume member account functionality
This helps authorized users assume other members account so they can log in and see what other users are seeing.
On Admin Page
Add end point
In file app\src\utils\apiEndPoints\auth.js
const auth = {
//
//
// ... append
assumeMemberAccount: {
v1: {
...defaults.methods.POST,
...defaults.versions.v1,
uri: '/admin/:accountId/:memberIdToAssume',
},
},
}
``
// +++++++++++++++++++++++++++++++++++++++++++++++++++
Add below useEffect to `app\src\pages\account\tenant\LoginPage\index.tsx`
```jsx
// to assume account
useEffect(() => {
let token;
try {
token = atob(props.location.query.tk);
} catch (error) {
token = null;
}
if (token) {
props.dispatch({
type: "login/assumeWithTokenObject",
payload: JSON.parse(token),
});
} else {
props.history.push("/");
}
return () => {};
}, []);
```
## Create a new effect
Create a new assume account effect in `app\src\models\auth.js`
```jsx
```
## Create a new service
In file `app\src\services\auth.js`
```jsx
export function assumeMemberAccount({ payload }) {
return callApi({
uriEndPoint: auth.assumeMemberAccount.v1,
pathParams: {
accountId: payload.accountId,
memberIdToAssume: payload.memberIdToAssume,
},
});
}
```
## Where you want to add the button to assume account.
```jsx
<Button
type="primary"
loading={this.state.loading === item.email}
onClick={async () => {
this.setState({ loading: item.email });
let responseObject = await apiUtils.callApiBeta({
uriEndPoint: apiEndPoints.authentication.assumeAuth,
pathParams: {
tenantId: item.tenantId,
email: item.email,
},
});
this.setState({ loading: "" });
console.log(responseObject);
var win = window.open(
`${appHost()}/user/assume?tk=` + btoa(JSON.stringify(responseObject)),
"_blank"
);
win.focus();
}}
>
Assume {"->"}
</Button>
```