Skip to content
Snippets Groups Projects
index.pug 3.35 KiB
Newer Older
doctype html
html
    include includes/head.pug
    sib-router(default-route='splash' route-prefix=lang)
        sib-route(name='splash')
        sib-route(name='account-creation')
        sib-route(name='mentor-dashboard')
        sib-route(name='entrepreneur-dashboard')
    include includes/components/widgets.pug

Benoit Alessandroni's avatar
Benoit Alessandroni committed
        #mentor-dashboard(hidden).no-sidebar
            include includes/mentor/dashboard.pug
        
Benoit Alessandroni's avatar
Benoit Alessandroni committed
        #entrepreneur-dashboard(hidden).no-sidebar
            include includes/entrepreneur/dashboard.pug
            
Benoit Alessandroni's avatar
Benoit Alessandroni committed
        #splash(hidden).no-sidebar.container.flex
            include includes/splash.pug

        #account-creation(hidden).no-sidebar.container
            include includes/account-creation.pug
        
        #public-dashboard(hidden).no-sidebar
            include includes/public/dashboard.pug
        #main-loader(hidden) Loading…

        class="sib-auth-provider"
        data-authority=`${sdn}`
        data-id="coopstarter"
    )

script(type='module').
      import { store } from 'https://unpkg.com/@startinblox/core@0.8';
      const sibAuth = document.querySelector('sib-auth');
      
      class CoopStarterLoginComponent extends HTMLElement {
        async connectedCallback() {
          mentor_login.onclick = () => this.triggerLogin();
          this.update();
        }

        async triggerLogin() {
          let loader = document.getElementById('main-loader');
          loader.removeAttribute('hidden');
          let loader = document.getElementById('main-loader');
          loader.removeAttribute('hidden');
          let user = await sibAuth.getUser();
          let idToken = await sibAuth.getUserIdToken();
          console.log(window.location);
          
          if ( !user && window.location.href.indexOf('public-dashboard/public-resource-detail') === -1) {
            console.log("We have no user and not in public")
            loader.setAttribute("hidden", true);
            window.dispatchEvent(
              new CustomEvent('requestNavigation', { detail: { route: 'splash' } })
            );

          if(!user && window.location.href.indexOf('public-dashboard/public-resource-detail') > -1) {
            console.log("We are targetting the public space !")
            //- window.dispatchEvent(
            //-   new CustomEvent('requestNavigation', { detail: { 
            //-     route: 'public-resource-detail'
            //-   } })
            //- );
            loader.setAttribute("hidden", true);
          }
          if (user && user.mentor_profile) {
            window.dispatchEvent(
              new CustomEvent('requestNavigation', { detail: { route: 'mentor-dashboard' } })
            );
          } else if (user && user.entrepreneur_profile) {
            window.dispatchEvent(
              new CustomEvent('requestNavigation', { detail: { route: 'entrepreneur-dashboard' } })
            );
          } else {
            window.dispatchEvent(
              new CustomEvent('requestNavigation', { detail: { route: 'account-creation' } })
            );
          }
        }
        empty(){}
        populate(){}
      }
      customElements.define('cs-login', CoopStarterLoginComponent);