Skip to content

Commit bbca2b8

Browse files
committed
added ddu domain as coordinator
1 parent c1f1ec7 commit bbca2b8

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

app/api/auth/[...nextauth]/options.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export const options: NextAuthOptions = {
7878
}
7979
,
8080
async jwt({ token , user} : {token : JWT , user : CustomUser}){
81-
8281
if(user)
8382
{
8483
token.role = user.role
@@ -115,11 +114,22 @@ export const options: NextAuthOptions = {
115114
{
116115
var userExist = await User.findOne({email : profile?.email});
117116
if(!userExist){
118-
const usertobecreated = await User.create({
117+
if(user.email?.endsWith("@ddu.ac.in")){
118+
const usertobecreated = await User.create({
119119
email : profile?.email,
120120
name : profile?.name,
121-
password : "1234"
121+
password : makeid(10),
122+
role : "Coordinator"
122123
})
124+
}
125+
else{
126+
const usertobecreated = await User.create({
127+
email : profile?.email,
128+
name : profile?.name,
129+
password : makeid(10)
130+
})
131+
}
132+
123133
}
124134
return true;
125135
}
@@ -135,14 +145,14 @@ export const options: NextAuthOptions = {
135145

136146
}
137147

138-
// function makeid(length : number) {
139-
// let result = '';
140-
// const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
141-
// const charactersLength = characters.length;
142-
// let counter = 0;
143-
// while (counter < length) {
144-
// result += characters.charAt(Math.floor(Math.random() * charactersLength));
145-
// counter += 1;
146-
// }
147-
// return result;
148-
// }
148+
function makeid(length : number) {
149+
let result = '';
150+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
151+
const charactersLength = characters.length;
152+
let counter = 0;
153+
while (counter < length) {
154+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
155+
counter += 1;
156+
}
157+
return result;
158+
}

0 commit comments

Comments
 (0)