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

feat: use same token for teams #163

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ export default class Api extends Component {
this.apiClient.basePath = basePath;
this.bearer = this.apiClient.authentications.Bearer;
const currentLogin = this.helper.getProp("current_login") as string || "user";
const currentUserType = this.helper.getProp("current_user_type") as string || "user";
const tokenObj = this.helper.getProp("token") as JsonObject || {};
this.bearer.apiKey = `Bearer ${tokenObj[currentLogin]}`;
if (currentUserType === "team") {
const teamId = this.helper.getProp("team_id");
console.log({teamId})
this.apiClient.defaultHeaders = { "X-auth-teamid": teamId };
}

this.botApi = new this.zaun.BotApi();
this.authApi = new this.zaun.AuthApi();
Expand Down
16 changes: 6 additions & 10 deletions components/users/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,12 @@ export default class User extends Component {
response.body.teams.filter((team: any) => team.username === name) : [];

if (teams.length > 0) {
const result = await this.helper.toPromise(
this.api.authApi,
this.api.authApi.tokensPost,
{
type: "team",
teamId: teams[0].teamId
}
);
const token = result.data.id;
this.setToken({ name, type: "team" }, token);
const team = teams[0];
const currentToken = this.helper.getProp("token") as JsonObject || {}
const currentLogin = this.helper.getProp("current_login") as string || "user";

this.setToken({ name, type: "team" }, currentToken[currentLogin] as string);
this.helper.setProp("team_id", team.teamId);
this.helper.setProp("current_login", name);
this.helper.setProp("current_user_type", "team");
console.log(`Switched to team: ${colors.green(name)}`);
Expand Down
7 changes: 7 additions & 0 deletions lib/components/api/api.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions lib/components/users/user.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.