Get org errors

This commit is contained in:
Rotimi Best
2023-05-16 16:30:30 +01:00
parent 68e1dbb1b5
commit 150fa92005
2 changed files with 16 additions and 6 deletions
+5 -2
View File
@@ -151,10 +151,13 @@
if (typeof window !== 'undefined') {
const debug = localStorage.getItem('role') === 'student';
const matches = host.match(/([a-z0-9]+).*classroomio[.]com/);
const answer = Array.isArray(matches) ? !!matches[1] : false;
const subdomain = matches?.[1] ?? '';
const answer = Array.isArray(matches)
? !!subdomain && subdomain !== 'www'
: false;
$appStore.isStudentDomain = debug || answer;
$appStore.siteNameFromDomain = debug ? 'codingdojo' : matches?.[1] ?? '';
$appStore.siteNameFromDomain = debug ? 'codingdojo' : subdomain;
}
}
+11 -4
View File
@@ -1,4 +1,5 @@
import get from 'lodash/get';
import isEmpty from 'lodash/isEmpty';
import { goto } from '@sapper/app';
import { supabase } from '../../functions/supabase';
import { orgs, currentOrg, orgAudience, orgTeam } from '../../store/org';
@@ -157,11 +158,17 @@ export async function getCourseBySiteName(siteName) {
export async function getCurrentOrg(siteName) {
const { data, error } = await supabase
.from('organization')
.select(`*`)
.eq('siteName', siteName)
.single();
.select(
`
id,
name,
siteName,
avatar_url
`
)
.eq('siteName', siteName);
if (error || !data) {
if (error || isEmpty(data)) {
console.error('Error getOrganization', error);
return goto('/404');
}