0

I have a third party module in my app.module.ts that needs to know whether a user logs in with or without a "www" in their url to correctly redirect them after authentication. So, setup looks like:

app.module.ts

...
@NgModule({
    declarations: [
        AppComponent
    ],
    imports     : [
        ...
        ThirdPartyAuthModule.initAuth(environment.authConfig),
        ...
    ],
    bootstrap   : [
        AppComponent
    ]
})
export class AppModule
{
}

I want to get somehow get the url into that authConfig variable. Is this possible with Angular?

1
  • you can actually use APP_INITIALIZER and write your logic in it.
    – Aravind
    Apr 10, 2020 at 22:23

1 Answer 1

1

You could always use window.location.href

https://stackblitz.com/edit/angular-href-1

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { environment } from '../environments/environment';

const authConfig = environment.authConfig;
// Add param below to your auth config
const href = window.location.href;
const isHttp = href.includes('http://');
const isHttps = href.includes('https://');
const hasWWW = href.includes('www');;

@NgModule({
  imports:      [
    BrowserModule,
    FormsModule,
    // ThirdPartyAuthModule.initAuth(authConfig),
    ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.