fix: auth flow bug on joining course

This commit is contained in:
Rotimi Best
2023-12-05 08:31:26 +03:00
parent 8fc3a5e1fc
commit 6fa1d0fcfb
12 changed files with 69 additions and 86 deletions
@@ -47,9 +47,11 @@
height="h-10"
className="mr-2"
/>
<h4 class="dark:text-white text-xl mt-0">
{$currentOrg.name ? $currentOrg.name : 'ClassroomIO'}
</h4>
<a href="/">
<h4 class="dark:text-white text-xl mt-0">
{$currentOrg.name ? $currentOrg.name : 'ClassroomIO'}
</h4>
</a>
</div>
{/if}
<form
@@ -5,25 +5,17 @@
import { VARIANTS } from '$lib/components/PrimaryButton/constants';
import { supabase } from '$lib/utils/functions/supabase';
import { capturePosthogEvent } from '$lib/utils/services/posthog';
import { currentOrg, orgs } from '$lib/utils/store/org';
import { currentOrg, orgs, defaultCurrentOrgState } from '$lib/utils/store/org';
import { user, profile, defaultProfileState, defaultUserState } from '$lib/utils/store/user';
async function logout() {
const { error } = await supabase.auth.signOut();
console.error('Error logging out: ', error);
// Reset organization values, TODO: consider abstracting if needed in other places
currentOrg.set({
id: '',
name: '',
shortName: '',
siteName: '',
avatar_url: '',
memberId: '',
role_id: '',
landingpage: {},
theme: ''
})
orgs.set([]);
currentOrg.set(defaultCurrentOrgState);
orgs.set([]);
user.set(defaultUserState);
profile.set(defaultProfileState);
capturePosthogEvent('user_logged_out');
posthog.reset();
@@ -5,6 +5,7 @@
import ChevronRightIcon from 'carbon-icons-svelte/lib/ChevronRight.svelte';
import ArrowLeftIcon from 'carbon-icons-svelte/lib/ArrowLeft.svelte';
import ArrowUpRightIcon from 'carbon-icons-svelte/lib/ArrowUpRight.svelte';
import { currentOrgDomain } from '$lib/utils/store/org';
import IconButton from '$lib/components/IconButton/index.svelte';
import CloseButton from '$lib/components/Buttons/Close/index.svelte';
@@ -128,12 +129,9 @@
loading = false;
syncCourseStore(course);
}
/**
* 1. Use all you have for editing now
* 2. Make course one interface we might need to computation
*/
async function handlePreview() {
const link = `${window.location.origin}/course/${course.slug}`;
const link = `${$currentOrgDomain}/course/${course.slug}`;
window.open(link, '_blank');
}
</script>
@@ -4,7 +4,7 @@
import getCurrencyFormatter from '$lib/utils/functions/getCurrencyFormatter';
import { isCourseFree } from '$lib/utils/functions/course';
import { getStudentInviteLink } from '$lib/utils/functions/course';
import { currentOrg } from '$lib/utils/store/org';
import { currentOrg, currentOrgDomain } from '$lib/utils/store/org';
import { goto } from '$app/navigation';
import PaymentModal from './PaymentModal.svelte';
import type { Course } from '$lib/utils/types';
@@ -17,6 +17,7 @@
export let startCoursePayment = false;
export let mobile = false;
let openModal = false;
let calculatedCost = 0;
let discount = 0;
let formatter: Intl.NumberFormat | undefined;
@@ -39,11 +40,13 @@
course_free: isFree
});
if (isFree) {
const link = getStudentInviteLink(courseData, $currentOrg.siteName);
const link = getStudentInviteLink(courseData, $currentOrg.siteName, $currentOrgDomain);
goto(link);
} else {
startCoursePayment = true;
openModal = true;
}
startCoursePayment = false;
}
function setFormatter(currency: string | undefined) {
@@ -62,10 +65,11 @@
$: discount = get(courseData, 'metadata.discount', 0);
$: calculatedCost = calcDisc(discount, courseData.cost || 0, !!courseData.metadata.showDiscount);
$: isFree = isCourseFree(calculatedCost);
$: startCoursePayment && handleJoinCourse();
</script>
<PaymentModal
bind:open={startCoursePayment}
bind:open={openModal}
paymentLink={get(courseData, 'metadata.paymentLink', '')}
courseName={courseData.title}
teacherEmail={getTeacherEmail(courseData.group)}
@@ -66,8 +66,10 @@
height="h-20"
/>
<div class="mt-5">
<p class="dark:text-white text-lg font-bold whitespace-nowrap truncate">
<div class="mt-5 flex justify-center w-full">
<p
class="dark:text-white text-lg font-bold whitespace-nowrap truncate max-w-[80%] text-center"
>
{$profile.fullname}
</p>
</div>
@@ -3,7 +3,7 @@ import type { Course } from '../types';
export const isCourseFree = (cost: number) => !(Number(cost) > 0);
export const getStudentInviteLink = (_course: Course, orgSiteName: string) => {
export const getStudentInviteLink = (_course: Course, orgSiteName: string, origin: string) => {
const hash = encodeURIComponent(
btoa(
JSON.stringify({
@@ -15,7 +15,7 @@ export const getStudentInviteLink = (_course: Course, orgSiteName: string) => {
)
);
return `https://${orgSiteName}.classroomio.com/invite/s/${hash}`;
return `${origin}/invite/s/${hash}`;
};
export const getTextFromHTML = (html: string): string => {
@@ -27,7 +27,7 @@ export const getTextFromHTML = (html: string): string => {
return dummyDiv.textContent?.trim() || '';
};
const tagsToReplace = {
const tagsToReplace: { [k: string]: string } = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;'
+5 -3
View File
@@ -6,8 +6,7 @@ import type { CurrentOrg, OrgTeamMember, OrgAudience } from '../types/org';
import { ROLE } from '$lib/utils/constants/roles';
import type { UserLessonDataType } from '$lib/utils/types';
export const orgs = writable<CurrentOrg[]>([]);
export const currentOrg: Writable<CurrentOrg> = writable({
export const defaultCurrentOrgState: CurrentOrg = {
id: '',
name: '',
shortName: '',
@@ -17,7 +16,10 @@ export const currentOrg: Writable<CurrentOrg> = writable({
role_id: '',
landingpage: {},
theme: ''
});
};
export const orgs = writable<CurrentOrg[]>([]);
export const currentOrg: Writable<CurrentOrg> = writable(defaultCurrentOrgState);
export const orgAudience = writable<OrgAudience[]>([]);
export const orgTeam = writable<OrgTeamMember[]>([]);
export const isOrgAdmin = derived(
+19 -11
View File
@@ -1,21 +1,15 @@
import { writable } from 'svelte/store';
import type { User } from '@supabase/supabase-js';
export const user = writable<{
interface UserStore {
openAuthModal: boolean;
fetchingUser: boolean;
isLoggedIn: boolean;
currentSession: User | undefined;
expiresAt: number;
}>({
openAuthModal: false,
fetchingUser: false,
isLoggedIn: false,
currentSession: undefined,
expiresAt: 0
});
}
export const profile = writable<{
interface ProfileStore {
id: string | undefined;
fullname: string;
avatar_url: string;
@@ -27,7 +21,17 @@ export const profile = writable<{
goal: string;
source: string;
telegram_chat_id: number | null;
}>({
}
export const defaultUserState: UserStore = {
openAuthModal: false,
fetchingUser: false,
isLoggedIn: false,
currentSession: undefined,
expiresAt: 0
};
export const defaultProfileState: ProfileStore = {
id: undefined,
fullname: '',
avatar_url: 'https://pbs.twimg.com/profile_images/1416443682157473795/dGtFbtht_normal.jpg',
@@ -38,4 +42,8 @@ export const profile = writable<{
goal: '',
source: '',
telegram_chat_id: null
});
};
export const user = writable<UserStore>(defaultUserState);
export const profile = writable<ProfileStore>(defaultProfileState);