forked from transitive-bullshit/nextjs-notion-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathacl.ts
55 lines (49 loc) · 1.14 KB
/
acl.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { PageProps } from './types'
export async function pageAcl({
site,
recordMap,
pageId
}: PageProps): Promise<PageProps> {
if (!site) {
return {
error: {
statusCode: 404,
message: 'Unable to resolve notion site'
}
}
}
if (!recordMap) {
return {
error: {
statusCode: 404,
message: `Unable to resolve page for domain "${site.domain}". Notion page "${pageId}" not found.`
}
}
}
const keys = Object.keys(recordMap.block)
const rootKey = keys[0]
if (!rootKey) {
return {
error: {
statusCode: 404,
message: `Unable to resolve page for domain "${site.domain}". Notion page "${pageId}" invalid data.`
}
}
}
const rootValue = recordMap.block[rootKey]?.value
const rootSpaceId = rootValue?.space_id
if (
rootSpaceId &&
site.rootNotionSpaceId &&
rootSpaceId !== site.rootNotionSpaceId
) {
if (process.env.NODE_ENV) {
return {
error: {
statusCode: 404,
message: `Notion page "${pageId}" doesn't belong to the Notion workspace owned by "${site.domain}".`
}
}
}
}
}