How can i show the data in angular component after authentication is done in a Pop up window?










0















I have to do the authentication in angular by GitLab. So i have created a button in my angular-app. After click on that button this function will be call the login() which will open a pop up. After log in successfully i got the access token by which i will get the data from GitLab.



 isLoggedIn = true;
api: any;
public test: any;
accessToken: any;

constructor(
private router: Router,
private route: ActivatedRoute,
private gitLabApi: GitLabApiService,
private cd: ChangeDetectorRef
)



ngOnInit()
this.accessToken = localStorage.getItem('access_token');
if (this.accessToken)
this.apiRequest();
else this.accessToken)
localStorage.setItem('access_token', this.accessToken);

window.close();
this.router.navigate(['manager']);
this.apiRequest();



logOut()
if (this.accessToken)
console.log(localStorage.removeItem('access_token'));
this.isLoggedIn = false;
this.router.navigate(['logginIn']);


this.sideBar.afterLogIn = false;



apiRequest()
this.gitLabApi.getProjectApi(this.accessToken).subscribe(
apiData =>
this.api = apiData;
// console.log(this.api);
this.cd.markForCheck();
this.isLoggedIn = true;
,
error => console.log(error.message)
);
this.sideBar.getCommitDetail();
this.sideBar.afterLogIn = true;


logIn()
//window.location.href = authUrl;
window.open(authUrl, "pop Up", "width=250, height= 250 ")



But after closing the pop up in ngOnInit, its not redirect to my page.
Instead of window.open if i use window.location.href then its working fine. Now how can i achieve the same functionality with window.open ?










share|improve this question


























    0















    I have to do the authentication in angular by GitLab. So i have created a button in my angular-app. After click on that button this function will be call the login() which will open a pop up. After log in successfully i got the access token by which i will get the data from GitLab.



     isLoggedIn = true;
    api: any;
    public test: any;
    accessToken: any;

    constructor(
    private router: Router,
    private route: ActivatedRoute,
    private gitLabApi: GitLabApiService,
    private cd: ChangeDetectorRef
    )



    ngOnInit()
    this.accessToken = localStorage.getItem('access_token');
    if (this.accessToken)
    this.apiRequest();
    else this.accessToken)
    localStorage.setItem('access_token', this.accessToken);

    window.close();
    this.router.navigate(['manager']);
    this.apiRequest();



    logOut()
    if (this.accessToken)
    console.log(localStorage.removeItem('access_token'));
    this.isLoggedIn = false;
    this.router.navigate(['logginIn']);


    this.sideBar.afterLogIn = false;



    apiRequest()
    this.gitLabApi.getProjectApi(this.accessToken).subscribe(
    apiData =>
    this.api = apiData;
    // console.log(this.api);
    this.cd.markForCheck();
    this.isLoggedIn = true;
    ,
    error => console.log(error.message)
    );
    this.sideBar.getCommitDetail();
    this.sideBar.afterLogIn = true;


    logIn()
    //window.location.href = authUrl;
    window.open(authUrl, "pop Up", "width=250, height= 250 ")



    But after closing the pop up in ngOnInit, its not redirect to my page.
    Instead of window.open if i use window.location.href then its working fine. Now how can i achieve the same functionality with window.open ?










    share|improve this question
























      0












      0








      0


      2






      I have to do the authentication in angular by GitLab. So i have created a button in my angular-app. After click on that button this function will be call the login() which will open a pop up. After log in successfully i got the access token by which i will get the data from GitLab.



       isLoggedIn = true;
      api: any;
      public test: any;
      accessToken: any;

      constructor(
      private router: Router,
      private route: ActivatedRoute,
      private gitLabApi: GitLabApiService,
      private cd: ChangeDetectorRef
      )



      ngOnInit()
      this.accessToken = localStorage.getItem('access_token');
      if (this.accessToken)
      this.apiRequest();
      else this.accessToken)
      localStorage.setItem('access_token', this.accessToken);

      window.close();
      this.router.navigate(['manager']);
      this.apiRequest();



      logOut()
      if (this.accessToken)
      console.log(localStorage.removeItem('access_token'));
      this.isLoggedIn = false;
      this.router.navigate(['logginIn']);


      this.sideBar.afterLogIn = false;



      apiRequest()
      this.gitLabApi.getProjectApi(this.accessToken).subscribe(
      apiData =>
      this.api = apiData;
      // console.log(this.api);
      this.cd.markForCheck();
      this.isLoggedIn = true;
      ,
      error => console.log(error.message)
      );
      this.sideBar.getCommitDetail();
      this.sideBar.afterLogIn = true;


      logIn()
      //window.location.href = authUrl;
      window.open(authUrl, "pop Up", "width=250, height= 250 ")



      But after closing the pop up in ngOnInit, its not redirect to my page.
      Instead of window.open if i use window.location.href then its working fine. Now how can i achieve the same functionality with window.open ?










      share|improve this question














      I have to do the authentication in angular by GitLab. So i have created a button in my angular-app. After click on that button this function will be call the login() which will open a pop up. After log in successfully i got the access token by which i will get the data from GitLab.



       isLoggedIn = true;
      api: any;
      public test: any;
      accessToken: any;

      constructor(
      private router: Router,
      private route: ActivatedRoute,
      private gitLabApi: GitLabApiService,
      private cd: ChangeDetectorRef
      )



      ngOnInit()
      this.accessToken = localStorage.getItem('access_token');
      if (this.accessToken)
      this.apiRequest();
      else this.accessToken)
      localStorage.setItem('access_token', this.accessToken);

      window.close();
      this.router.navigate(['manager']);
      this.apiRequest();



      logOut()
      if (this.accessToken)
      console.log(localStorage.removeItem('access_token'));
      this.isLoggedIn = false;
      this.router.navigate(['logginIn']);


      this.sideBar.afterLogIn = false;



      apiRequest()
      this.gitLabApi.getProjectApi(this.accessToken).subscribe(
      apiData =>
      this.api = apiData;
      // console.log(this.api);
      this.cd.markForCheck();
      this.isLoggedIn = true;
      ,
      error => console.log(error.message)
      );
      this.sideBar.getCommitDetail();
      this.sideBar.afterLogIn = true;


      logIn()
      //window.location.href = authUrl;
      window.open(authUrl, "pop Up", "width=250, height= 250 ")



      But after closing the pop up in ngOnInit, its not redirect to my page.
      Instead of window.open if i use window.location.href then its working fine. Now how can i achieve the same functionality with window.open ?







      angular






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 13:06









      KaziKazi

      9610




      9610






















          2 Answers
          2






          active

          oldest

          votes


















          0














          you can check this ng-bootstrap






          share|improve this answer























          • actually i am not looking any css. I want to do the authentication in my pop up window. Here nothing to do with the css i guess

            – Kazi
            Nov 13 '18 at 13:16


















          0














          The issue is that window.close is closing the window which the router then tries to navigate. You need the logIn method to handle the routing logic for the original instance of the app once the login window is closed. Example:



          logIn() 
          const newwindow = window.open(authUrl, "pop Up", "width=250, height= 250 ");

          newwindow.onbeforeunload = () =>
          if (localStorage.getItem('access_token'))
          this.router.navigate(['manager']);
          this.apiRequest();
          else
          // login failed








          share|improve this answer























          • hi unfortunently its not working. Before windows is closing or user logged in, ` newwindow.onbeforeunload = () => if (localStorage.getItem('access_token')) this.router.navigate(['manager']); this.apiRequest(); else // login failed ` this line of code is executing. @teddy-sterne

            – Kazi
            Nov 13 '18 at 13:49











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281680%2fhow-can-i-show-the-data-in-angular-component-after-authentication-is-done-in-a-p%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          you can check this ng-bootstrap






          share|improve this answer























          • actually i am not looking any css. I want to do the authentication in my pop up window. Here nothing to do with the css i guess

            – Kazi
            Nov 13 '18 at 13:16















          0














          you can check this ng-bootstrap






          share|improve this answer























          • actually i am not looking any css. I want to do the authentication in my pop up window. Here nothing to do with the css i guess

            – Kazi
            Nov 13 '18 at 13:16













          0












          0








          0







          you can check this ng-bootstrap






          share|improve this answer













          you can check this ng-bootstrap







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 13:12









          Skandar B.ASkandar B.A

          214




          214












          • actually i am not looking any css. I want to do the authentication in my pop up window. Here nothing to do with the css i guess

            – Kazi
            Nov 13 '18 at 13:16

















          • actually i am not looking any css. I want to do the authentication in my pop up window. Here nothing to do with the css i guess

            – Kazi
            Nov 13 '18 at 13:16
















          actually i am not looking any css. I want to do the authentication in my pop up window. Here nothing to do with the css i guess

          – Kazi
          Nov 13 '18 at 13:16





          actually i am not looking any css. I want to do the authentication in my pop up window. Here nothing to do with the css i guess

          – Kazi
          Nov 13 '18 at 13:16













          0














          The issue is that window.close is closing the window which the router then tries to navigate. You need the logIn method to handle the routing logic for the original instance of the app once the login window is closed. Example:



          logIn() 
          const newwindow = window.open(authUrl, "pop Up", "width=250, height= 250 ");

          newwindow.onbeforeunload = () =>
          if (localStorage.getItem('access_token'))
          this.router.navigate(['manager']);
          this.apiRequest();
          else
          // login failed








          share|improve this answer























          • hi unfortunently its not working. Before windows is closing or user logged in, ` newwindow.onbeforeunload = () => if (localStorage.getItem('access_token')) this.router.navigate(['manager']); this.apiRequest(); else // login failed ` this line of code is executing. @teddy-sterne

            – Kazi
            Nov 13 '18 at 13:49
















          0














          The issue is that window.close is closing the window which the router then tries to navigate. You need the logIn method to handle the routing logic for the original instance of the app once the login window is closed. Example:



          logIn() 
          const newwindow = window.open(authUrl, "pop Up", "width=250, height= 250 ");

          newwindow.onbeforeunload = () =>
          if (localStorage.getItem('access_token'))
          this.router.navigate(['manager']);
          this.apiRequest();
          else
          // login failed








          share|improve this answer























          • hi unfortunently its not working. Before windows is closing or user logged in, ` newwindow.onbeforeunload = () => if (localStorage.getItem('access_token')) this.router.navigate(['manager']); this.apiRequest(); else // login failed ` this line of code is executing. @teddy-sterne

            – Kazi
            Nov 13 '18 at 13:49














          0












          0








          0







          The issue is that window.close is closing the window which the router then tries to navigate. You need the logIn method to handle the routing logic for the original instance of the app once the login window is closed. Example:



          logIn() 
          const newwindow = window.open(authUrl, "pop Up", "width=250, height= 250 ");

          newwindow.onbeforeunload = () =>
          if (localStorage.getItem('access_token'))
          this.router.navigate(['manager']);
          this.apiRequest();
          else
          // login failed








          share|improve this answer













          The issue is that window.close is closing the window which the router then tries to navigate. You need the logIn method to handle the routing logic for the original instance of the app once the login window is closed. Example:



          logIn() 
          const newwindow = window.open(authUrl, "pop Up", "width=250, height= 250 ");

          newwindow.onbeforeunload = () =>
          if (localStorage.getItem('access_token'))
          this.router.navigate(['manager']);
          this.apiRequest();
          else
          // login failed









          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 13:19









          Teddy SterneTeddy Sterne

          7,00311529




          7,00311529












          • hi unfortunently its not working. Before windows is closing or user logged in, ` newwindow.onbeforeunload = () => if (localStorage.getItem('access_token')) this.router.navigate(['manager']); this.apiRequest(); else // login failed ` this line of code is executing. @teddy-sterne

            – Kazi
            Nov 13 '18 at 13:49


















          • hi unfortunently its not working. Before windows is closing or user logged in, ` newwindow.onbeforeunload = () => if (localStorage.getItem('access_token')) this.router.navigate(['manager']); this.apiRequest(); else // login failed ` this line of code is executing. @teddy-sterne

            – Kazi
            Nov 13 '18 at 13:49

















          hi unfortunently its not working. Before windows is closing or user logged in, ` newwindow.onbeforeunload = () => if (localStorage.getItem('access_token')) this.router.navigate(['manager']); this.apiRequest(); else // login failed ` this line of code is executing. @teddy-sterne

          – Kazi
          Nov 13 '18 at 13:49






          hi unfortunently its not working. Before windows is closing or user logged in, ` newwindow.onbeforeunload = () => if (localStorage.getItem('access_token')) this.router.navigate(['manager']); this.apiRequest(); else // login failed ` this line of code is executing. @teddy-sterne

          – Kazi
          Nov 13 '18 at 13:49


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281680%2fhow-can-i-show-the-data-in-angular-component-after-authentication-is-done-in-a-p%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3