CLASSROOMIO-T-36: Student authentication flow

Co-authored-by: Rotimi Best <rotimiibitoyeemma@gmail.com>

Merge-request: CLASSROOMIO-MR-12
Merged-by: Digdippa Team <digdippa@gmail.com>
This commit is contained in:
Rotimi Best
2023-05-16 04:31:45 +00:00
committed by Space Cloud
co-authored by Rotimi Best
parent 8d0f1e4de1
commit 68e1dbb1b5
12 changed files with 387 additions and 38 deletions
+56 -16
View File
@@ -15,22 +15,26 @@
import Tailwindcss from '../components/Tailwindcss.svelte';
import LandingNavigation from '../components/Navigation/index.svelte';
import OrgNavigation from '../components/Navigation/app.svelte';
import LMSNavigation from '../components/Navigation/lms.svelte';
import OrgLandingPage from '../components/Org/LandingPage/index.svelte';
import Snackbar from '../components/Snackbar/index.svelte';
import Backdrop from '../components/Backdrop/index.svelte';
import OrgSideBar from '../components/Org/SideBar.svelte';
import LMSSideBar from '../components/LMS/SideBar.svelte';
// import SideBar from "../components/SideBar/index.svelte";
// import Footer from '../components/Footer/index.svelte';
import Apps from '../components/Apps/index.svelte';
import { handleAuthChange } from '../utils/functions/api';
import { isCoursesPage, isOrgPage, isLMSPage } from '../utils/functions/app';
import showAppsSideBar from '../utils/functions/showAppsSideBar';
import { user, profile } from '../utils/store/user';
import { getSupabase } from '../utils/functions/supabase';
import { isMobile } from '../utils/store/useMobile';
import { ROUTES_TO_HIDE_NAV, ROUTE } from '../utils/constants/routes';
import { getOrganizations } from '../utils/services/org';
import { getOrganizations, getCurrentOrg } from '../utils/services/org';
import { toggleBodyByTheme } from '../utils/functions/app';
import { appStore } from '../utils/store/app';
import { currentOrg } from '../utils/store/org';
export let segment;
export let config;
@@ -46,6 +50,7 @@
});
async function getProfile() {
const params = new URLSearchParams(window.location.search);
// Get user profile
const authUser = supabase.auth.user();
console.log('Get user profile', authUser);
@@ -85,6 +90,28 @@
// Set user in sentry
Sentry.setUser($profile);
if ($appStore.isStudentDomain) {
const { data, error } = await supabase
.from('organizationmember')
.insert({
organization_id: $currentOrg.id,
profile_id: $profile.id,
role_id: 3,
});
if (error) {
console.error('Error adding user to organisation', error);
} else {
console.log('Success adding user to organisation', data);
}
if (params.has('redirect')) {
goto(params.get('redirect'));
} else {
goto('/lms');
}
return;
}
goto(ROUTE.ONBOARDING);
}
$user.fetchingUser = false;
@@ -97,12 +124,16 @@
// Set user in sentry
Sentry.setUser($profile);
const orgRes = await getOrganizations($profile.id);
// student redirect
if ($appStore.isStudentDomain) {
// student redirect
if (params.has('redirect')) {
goto(params.get('redirect'));
} else {
goto('/lms');
}
} else {
const orgRes = await getOrganizations($profile.id);
// If user coming to login page, then
if (isEmpty(orgRes.orgs)) {
goto(ROUTE.ONBOARDING);
} else if (
@@ -123,18 +154,10 @@
const answer = Array.isArray(matches) ? !!matches[1] : false;
$appStore.isStudentDomain = debug || answer;
$appStore.siteNameFromDomain = debug ? 'startupscoo' : matches?.[1] ?? '';
$appStore.siteNameFromDomain = debug ? 'codingdojo' : matches?.[1] ?? '';
}
}
function isCoursePage(path) {
return /course[s]*\/[a-z 0-9 -]/.test(path);
}
function isOrgPage(path) {
return /org\/[a-z 0-9 -]/.test(path);
}
function handleResize() {
isMobile.update(() => window.innerWidth <= 760);
}
@@ -182,6 +205,10 @@
$appStore.isDark = localStorage.getItem('theme') === 'dark';
toggleBodyByTheme($appStore.isDark);
if ($appStore.isStudentDomain) {
getCurrentOrg($appStore.siteNameFromDomain);
}
return () => {
authListener.unsubscribe();
};
@@ -212,11 +239,17 @@
<Moon size="60" color="#1d4ed8" unit="px" duration="1s" />
</Backdrop>
{/if}
{#if !ROUTES_TO_HIDE_NAV.includes($page.path) && !isCoursePage(path)}
{#if $page.path.includes('org') || $page.path.includes('profile')}
{#if !ROUTES_TO_HIDE_NAV.includes($page.path) && !isCoursesPage(path)}
{#if isOrgPage($page.path) || $page.path.includes('profile')}
<OrgNavigation />
{:else if isLMSPage($page.path)}
<LMSNavigation />
{:else}
<LandingNavigation {segment} />
<LandingNavigation
{segment}
logo={$appStore.isStudentDomain ? $currentOrg.avatar_url : undefined}
orgName={$appStore.isStudentDomain ? $currentOrg.name : undefined}
/>
{/if}
{/if}
@@ -228,6 +261,13 @@
<slot />
</div>
</div>
{:else if isLMSPage($page.path)}
<div class="org-root w-full flex items-center justify-between">
<LMSSideBar />
<div class="org-slot bg-white dark:bg-gray-800">
<slot />
</div>
</div>
{:else}
<slot />
{/if}
+1
View File
@@ -0,0 +1 @@
Exercises
+1
View File
@@ -0,0 +1 @@
<h1>Your Journey into progress begins today. Welcome !!!</h1>
+1
View File
@@ -0,0 +1 @@
My Learning
+1
View File
@@ -0,0 +1 @@
Settings Page