-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
112 lines (106 loc) · 3.66 KB
/
index.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { getSession } from "next-auth/client"
import { useRouter } from 'next/router';
import { useEffect } from "react";
import { allowedPermissions } from "../utils/constants";
// function RedirectTo(to){
// const router = useRouter();
// useEffect(()=>{
// router.push(to)
// },[to])
// }
export async function getServerSideProps(ctx) {
const session = await getSession(ctx);
let userPermissions =null;
let personIdentifier = null;
if(session && session.data && session.data.userRoles)
{
userPermissions = JSON.parse(session.data?.userRoles);
personIdentifier = userPermissions && userPermissions.length > 0 ? userPermissions[0].personIdentifier : ""
}
if (process.env.NEXT_PUBLIC_LOGIN_PROVIDER !== "SAML") {
//Redirect to search after login
if (session && session.data) {
if (session.data.databaseUser && session.data.databaseUser.status == 0) {
return {
redirect: {
destination: "/noaccess",
permanent: false,
},
};
}
else if (userPermissions && userPermissions.some(role => role.roleLabel === allowedPermissions.Curator_Self)) {
return {
redirect: {
destination: `/curate/${personIdentifier}`,
permanent: false,
},
};
}
else if ( userPermissions && userPermissions.some(role => role.roleLabel === allowedPermissions.Curator_All || role.roleLabel === allowedPermissions.Reporter_All || role.roleLabel === allowedPermissions.Superuser)) {
return {
redirect: {
destination: "/search",
permanent: false,
},
};
} else {
return {
redirect: {
destination: "/noaccess",
permanent: false,
},
};
}
}
return {
redirect: {
destination: "/login",
permanent: false,
},
};
}
//Redirect to search after login
if (session && session.data) {
if (session.data.databaseUser && session.data.databaseUser.status == 0) {
return {
redirect: {
destination: "/noaccess",
permanent: false,
},
};
}
else if (userPermissions && userPermissions.some(role => role.roleLabel === allowedPermissions.Curator_Self)) {
return {
redirect: {
destination: `/curate/${personIdentifier}`,
permanent: false,
},
};
}
else if (userPermissions && userPermissions.some(role => role.roleLabel === allowedPermissions.Curator_All || role.roleLabel === allowedPermissions.Reporter_All || role.roleLabel === allowedPermissions.Superuser))
{
return {
redirect: {
destination: "/search",
permanent: false,
},
};
} else {
return {
redirect: {
destination: "/noaccess",
permanent: false,
},
};
}
}
return {
redirect: {
destination: "/api/saml/assert?callbackUrl=/search",
permanent: false,
},
};
}
export default function Home() {
return <></>;
}