File tree Expand file tree Collapse file tree 1 file changed +24
-14
lines changed
app/api/auth/[...nextauth] Expand file tree Collapse file tree 1 file changed +24
-14
lines changed Original file line number Diff line number Diff line change @@ -78,7 +78,6 @@ export const options: NextAuthOptions = {
78
78
}
79
79
,
80
80
async jwt ( { token , user} : { token : JWT , user : CustomUser } ) {
81
-
82
81
if ( user )
83
82
{
84
83
token . role = user . role
@@ -115,11 +114,22 @@ export const options: NextAuthOptions = {
115
114
{
116
115
var userExist = await User . findOne ( { email : profile ?. email } ) ;
117
116
if ( ! userExist ) {
118
- const usertobecreated = await User . create ( {
117
+ if ( user . email ?. endsWith ( "@ddu.ac.in" ) ) {
118
+ const usertobecreated = await User . create ( {
119
119
email : profile ?. email ,
120
120
name : profile ?. name ,
121
- password : "1234"
121
+ password : makeid ( 10 ) ,
122
+ role : "Coordinator"
122
123
} )
124
+ }
125
+ else {
126
+ const usertobecreated = await User . create ( {
127
+ email : profile ?. email ,
128
+ name : profile ?. name ,
129
+ password : makeid ( 10 )
130
+ } )
131
+ }
132
+
123
133
}
124
134
return true ;
125
135
}
@@ -135,14 +145,14 @@ export const options: NextAuthOptions = {
135
145
136
146
}
137
147
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
+ }
You can’t perform that action at this time.
0 commit comments