Patricia
Patricia

Reputation: 95

How can I check the caller url from my application in angular?

Our application will be accesible via a button on another application (from a different domain). We need to make sure our application is only accesible from that endpoint. How can we manage that?

I have tried using NavigationEnd but it's not showing the origin url, it only shows \

Extra info: Our front is in angular 11 and we are not allowed to use params on the url to check the origin of the call.

Thanks in advance

Upvotes: 0

Views: 339

Answers (1)

Bojan Kogoj
Bojan Kogoj

Reputation: 5649

Have you tried using document.referrer in Guard?

@Injectable()
class CanView implements CanActivate {

  canActivate(): boolean {
    return document.referrer.includes('https://stackoverflow.com');
  }
}

I would also suggest you save this to a service, so user can refresh.

Upvotes: 2

Related Questions