I have an Angular application that we have been using with auth0 for a while. We are working on integrating organization support into the code base.
In our app we have a component that is use to manage regular vs organizational login and invitations. when someone goes to a URL that is formatted like so.
/login?organization=XXXXXXXXXXX
It does direct me to the login for that organization. However, when the user is logged in their JWT token does not contain organization_id segment, and therefore we don’t know they are login as a member of an organization.
Am I missing something here?
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { AuthService } from '@auth0/auth0-angular';
@Component({
selector: 'app-login',
template: '',
styleUrls: []
})
export class LoginComponent implements OnInit {
constructor(
private auth: AuthService,
private activatedRoute: ActivatedRoute
) { }
ngOnInit(): void {
const queryParams = this.activatedRoute.snapshot.queryParams;
const params = this.activatedRoute.snapshot.params;
const queryParamsKeys = Object.keys(queryParams);
const paramsKeys = Object.keys(params);
if (queryParamsKeys.includes('invitation') && queryParamsKeys.includes('organization')) {
this.organizationLoginWithInvitation(queryParams.organization, queryParams.invitation);
}
else if (queryParamsKeys.includes('organization')) {
this.organizationLoginWithRedirect(queryParams.organization);
}
/*
else if (paramsKeys.includes('organization')) {
// Check for organization name with the API and if it exists get the organization ID from it.
// and redirect to the correct login page.
this.organizationLoginWithRedirect(params.organization);
}
else {
this.auth.loginWithRedirect({
redirect_uri: window.location.origin + '/auth/callback',
});
}
*/
}
private organizationLoginWithRedirect(organization: string): void {
const payload = {
organization: organization,
redirect_uri: window.location.origin + '/auth/callback',
};
this.auth.loginWithRedirect(payload);
}
private organizationLoginWithInvitation(organization: string, invitation: string): void {
this.auth.loginWithRedirect({
organization: organization,
invitation: invitation,
redirect_uri: window.location.origin + '/auth/callback',
});
}
}