fix: auth flow bug on joining course
This commit is contained in:
@@ -80,8 +80,8 @@
|
||||
const { user: authUser } = session || {};
|
||||
console.log('Get user', authUser);
|
||||
|
||||
if (!authUser) {
|
||||
goto('/login?redirect=/' + path);
|
||||
if (!authUser && !isPublicRoute($page.url.pathname)) {
|
||||
return goto('/login?redirect=/' + path);
|
||||
}
|
||||
|
||||
// Check if user has profile
|
||||
@@ -185,7 +185,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (!profileData) {
|
||||
if (!profileData && !isPublicRoute($page.url.pathname)) {
|
||||
goto('/login?redirect=/' + path);
|
||||
}
|
||||
}
|
||||
@@ -239,10 +239,10 @@
|
||||
if (data.skipAuth) return;
|
||||
|
||||
// Authentication Steps
|
||||
if (event === 'SIGNED_IN') {
|
||||
if (event === 'SIGNED_IN' || event === 'INITIAL_SESSION') {
|
||||
$user.fetchingUser = true;
|
||||
getProfile();
|
||||
} else if (!['INITIAL_SESSION', 'TOKEN_REFRESHED'].includes(event)) {
|
||||
} else if (!['TOKEN_REFRESHED'].includes(event)) {
|
||||
console.log('not logged in, go to login');
|
||||
return goto('/login');
|
||||
}
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
} from '$lib/utils/services/notification/notification';
|
||||
import { snackbar } from '$lib/components/Snackbar/store.js';
|
||||
import { capturePosthogEvent } from '$lib/utils/services/posthog';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
export let data;
|
||||
|
||||
let supabase = getSupabase();
|
||||
let loading = false;
|
||||
let refresh = false;
|
||||
|
||||
let disableSubmit = false;
|
||||
let formRef: HTMLFormElement;
|
||||
@@ -29,16 +29,9 @@
|
||||
async function handleSubmit() {
|
||||
loading = true;
|
||||
|
||||
if (refresh) {
|
||||
window.location.reload();
|
||||
refresh = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$profile.id || !$profile.email) {
|
||||
console.log('Profile not found', $profile);
|
||||
refresh = true;
|
||||
return;
|
||||
return goto(`/signup?redirect=${$page.url?.pathname || ''}`);
|
||||
}
|
||||
|
||||
const member = {
|
||||
@@ -124,19 +117,13 @@
|
||||
bind:formRef
|
||||
>
|
||||
<div class="mt-0 w-full">
|
||||
{#if refresh}
|
||||
<p class="dark:text-white text-sm font-light text-center">
|
||||
Something went wrong, please try again.
|
||||
</p>
|
||||
{:else}
|
||||
<h3 class="dark:text-white text-lg font-medium mt-0 mb-4 text-center">{data.name}</h3>
|
||||
<p class="dark:text-white text-sm font-light text-center">{data.description}</p>
|
||||
{/if}
|
||||
<h3 class="dark:text-white text-lg font-medium mt-0 mb-4 text-center">{data.name}</h3>
|
||||
<p class="dark:text-white text-sm font-light text-center">{data.description}</p>
|
||||
</div>
|
||||
|
||||
<div class="my-4 w-full flex justify-center items-center">
|
||||
<PrimaryButton
|
||||
label={refresh ? 'Try again' : 'Join Course'}
|
||||
label="Join Course"
|
||||
type="submit"
|
||||
isDisabled={disableSubmit || loading}
|
||||
isLoading={loading}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
let hasFetched = false;
|
||||
let progressPercentage = 0;
|
||||
let totalLessons = 0;
|
||||
let totalComPleted = 0;
|
||||
let totalCompleted = 0;
|
||||
|
||||
async function getCourses(userId: string | undefined, orgId: string) {
|
||||
if (hasFetched || !userId || !orgId) {
|
||||
@@ -32,10 +32,10 @@
|
||||
}
|
||||
|
||||
function calcTotalProgress(courses: Course[]) {
|
||||
totalComPleted = courses.reduce((acc, cur) => acc + (cur.progress_rate || 0), 0);
|
||||
totalCompleted = courses.reduce((acc, cur) => acc + (cur.progress_rate || 0), 0);
|
||||
totalLessons = courses.reduce((acc, cur) => acc + (cur.total_lessons || 0), 0);
|
||||
|
||||
progressPercentage = Math.round((totalComPleted / totalLessons) * 100);
|
||||
progressPercentage = Math.round((totalCompleted / totalLessons) * 100) || 0;
|
||||
}
|
||||
|
||||
$: getCourses($profile.id, $currentOrg.id);
|
||||
@@ -93,7 +93,7 @@
|
||||
</p>
|
||||
{#if totalLessons > 0}
|
||||
<p class="text-xs font-normal text-[#656565] dark:text-white">
|
||||
{totalComPleted}/{totalLessons} lessons completed
|
||||
{totalCompleted}/{totalLessons} lessons completed
|
||||
</p>
|
||||
{:else}
|
||||
<p class="text-xs font-normal text-[#656565] dark:text-white">No courses started</p>
|
||||
|
||||
@@ -7,16 +7,14 @@
|
||||
import { LOGIN_FIELDS } from '$lib/utils/constants/authentication';
|
||||
import AuthUI from '$lib/components/AuthUI/index.svelte';
|
||||
import { currentOrg } from '$lib/utils/store/org';
|
||||
import { onDestroy } from 'svelte';
|
||||
import { capturePosthogEvent } from '$lib/utils/services/posthog';
|
||||
|
||||
let formRef;
|
||||
let formRef: HTMLFormElement;
|
||||
let supabase = getSupabase();
|
||||
let fields = Object.assign({}, LOGIN_FIELDS);
|
||||
let submitError: string;
|
||||
let loading = false;
|
||||
let errors = {};
|
||||
// let reloadTimeout: NodeJS.Timeout;
|
||||
let errors = Object.assign({}, LOGIN_FIELDS);
|
||||
|
||||
let query = new URLSearchParams($page.url.search);
|
||||
let redirect = query.get('redirect');
|
||||
@@ -39,12 +37,6 @@
|
||||
console.log('data', data);
|
||||
if (error) throw error;
|
||||
|
||||
// reload page on org site cause for some reason the authlistener on +layout.svelte doesn't run sometimes
|
||||
// reloadTimeout = setTimeout(() => {
|
||||
// console.log('Forcing full page reload for auth listener');
|
||||
// window.location.reload();
|
||||
// }, 1500);
|
||||
|
||||
capturePosthogEvent('login', {
|
||||
email: fields.email
|
||||
});
|
||||
@@ -54,10 +46,6 @@
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
// onDestroy(() => {
|
||||
// clearTimeout(reloadTimeout);
|
||||
// });
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
||||
Reference in New Issue
Block a user