Skip to content
Snippets Groups Projects
index.pug 2.21 KiB
Newer Older
doctype html
html
    include includes/head.pug

    sib-router(default-route='splash')
        sib-route(name='splash')
        sib-route(name='mentor-new-account')
        sib-route(name='entrepreneur-new-account')
        sib-route(name='mentor-dashboard')
        sib-route(name='entrepreneur-dashboard')
        #mentor-dashboard(hidden).no-sidebar
            include includes/mentor/dashboard.pug
        
        #entrepreneur-dashboard(hidden).no-sidebar
            include includes/entrepreneur/dashboard.pug
            
        #splash(hidden).no-sidebar.flex 
            include includes/splash.pug

        #mentor-new-account(hidden).no-sidebar
            include includes/mentor/create.pug

        #entrepreneur-new-account(hidden).no-sidebar
            include includes/entrepreneur/create.pug
        class="sib-auth-provider"
        data-authority=`${sdn}`
        data-client_id=`${client_id}`,
        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();
          entrepreneur_login.onclick = () => this.triggerLogin();
          this.update();
        }

        async triggerLogin() {
          await sibAuth.login();
        }
        
        async update() {
          let user = await sibAuth.getUser();
          let idToken = await sibAuth.getUserIdToken();

          if ( !user ) {
            return;
          }
          user = await store.get(user);

          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' } })
            );
          }
        }
        empty(){}
        populate(){}
      }
      customElements.define('cs-login', CoopStarterLoginComponent);