Skip to content

Commit 6b6cf5b

Browse files
committed
Fixed public access to organizations.
1 parent 65ba793 commit 6b6cf5b

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Dates should be in`YYYY-MM-DD` format and versions are in [semantic versioning](
88
### Fixed
99

1010
- Improved performance of page loading.
11+
- Fixed public access to organizations.
1112

1213
### Maintenance
1314

src/routes/org/[orgid]/+layout.server.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { validate as isValidUUID } from 'uuid';
33

44
export async function load({ params, locals }) {
55
const { supabase } = locals;
6-
const { data: user } = await supabase.auth.getUser();
6+
const { data: userRecord } = await supabase.auth.getUser();
7+
const user = userRecord ? userRecord.user : null;
78

89
// Find the org corresponding to the orgid or the path string
910
let { data: org } = isValidUUID(params.orgid)
@@ -32,7 +33,7 @@ export async function load({ params, locals }) {
3233
.from('profiles')
3334
.select('*')
3435
.eq('orgid', org.id)
35-
.eq('personid', user.user ? user.user.id : 0)
36+
.eq('personid', user ? user.id : 0)
3637
.single(),
3738
supabase.from('roles').select('id', { count: 'exact', head: true }).eq('orgid', org.id),
3839
supabase.from('profiles').select('id', { count: 'exact', head: true }).eq('orgid', org.id),
@@ -56,18 +57,19 @@ export async function load({ params, locals }) {
5657
roles === null ||
5758
profiles === null ||
5859
processes === null ||
59-
changes === null ||
60-
shortRoles === null ||
61-
shortProcesses === null
60+
changes === null
6261
) {
6362
error(404, {
64-
message: 'Unable to retrieve organization data.'
63+
message:
64+
user === null
65+
? `Unable to show this organization. Try logging in with your organization email address, in case this organization restricted to members.`
66+
: `Unable to retrieve organization data.`
6567
});
6668
}
6769

6870
return {
6971
org,
70-
uid: user.user.id,
72+
uid: user ? user.id : null,
7173
member: profile !== null,
7274
admin: profile !== null && profile.admin,
7375
counts: {
@@ -76,7 +78,7 @@ export async function load({ params, locals }) {
7678
processes: processes,
7779
changes: changes
7880
},
79-
shortRoles: shortRoles,
80-
shortProcesses: shortProcesses
81+
shortRoles: shortRoles ?? [],
82+
shortProcesses: shortProcesses ?? []
8183
};
8284
}

0 commit comments

Comments
 (0)