fixed a few issues with auth
This commit is contained in:
		
							parent
							
								
									96facbf2e2
								
							
						
					
					
						commit
						f113c472fd
					
				
					 3 changed files with 15 additions and 6 deletions
				
			
		
							
								
								
									
										13
									
								
								src/auth.ts
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								src/auth.ts
									
										
									
									
									
								
							|  | @ -35,9 +35,10 @@ export function run(app) { | ||||||
| 
 | 
 | ||||||
| 				const users = await User.find({id: userInfo.id}); | 				const users = await User.find({id: userInfo.id}); | ||||||
| 				let userUuid = ''; | 				let userUuid = ''; | ||||||
|  | 
 | ||||||
| 				if (users.length === 0) { | 				if (users.length === 0) { | ||||||
| 					const newUser = new User({ | 					const newUser = new User({ | ||||||
| 						id: userInfo.id, | 						id: String(userInfo.data.id), | ||||||
| 						createdAt: new Date(), | 						createdAt: new Date(), | ||||||
| 
 | 
 | ||||||
| 						username: userInfo.data.username, | 						username: userInfo.data.username, | ||||||
|  | @ -50,12 +51,18 @@ export function run(app) { | ||||||
| 					userUuid = newUser.get('uuid'); | 					userUuid = newUser.get('uuid'); | ||||||
| 					newUser.save(); | 					newUser.save(); | ||||||
| 				} else { | 				} else { | ||||||
| 					userUuid = users[0].get('uuid'); | 					const user = users[0]; | ||||||
|  | 					userUuid = user.get('uuid'); | ||||||
|  | 
 | ||||||
|  | 					user.set('id', String(userInfo.data.id)); | ||||||
|  | 					user.set('username', userInfo.data.username); | ||||||
|  | 					user.set('discriminator', userInfo.data.discriminator); | ||||||
|  | 					user.set('avatar', userInfo.data.avatar); | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				req.session!.discord = userInfo.data; | 				req.session!.discord = userInfo.data; | ||||||
| 				req.session!.uuid = userUuid; | 				req.session!.uuid = userUuid; | ||||||
| 				res.send(`hi ${userInfo.data.username}#${userInfo.data.discriminator}<br><img src="https://media.discordapp.net/avatars/${userInfo.data.id}/${userInfo.data.avatar}.png"><br>ur useruuid is ${userUuid}`); | 				res.send(`logged in as ${userInfo.data.username}#${userInfo.data.discriminator}<br><img src="https://media.discordapp.net/avatars/${userInfo.data.id}/${userInfo.data.avatar}.png"><br>ur useruuid is ${userUuid}`); | ||||||
| 			} catch(err) { | 			} catch(err) { | ||||||
| 				res.send(`whoooops<br>${err}`); | 				res.send(`whoooops<br>${err}`); | ||||||
| 				console.error(err); | 				console.error(err); | ||||||
|  |  | ||||||
|  | @ -85,9 +85,11 @@ db.then(() => { | ||||||
| 		for (const doc of files) { | 		for (const doc of files) { | ||||||
| 			const d = doc.toJSON(); | 			const d = doc.toJSON(); | ||||||
| 			const user = await User.find({uuid: d.uploader}); | 			const user = await User.find({uuid: d.uploader}); | ||||||
|  | 			if (user) { | ||||||
| 				d.uploaderJSON = user[0].toJSON(); // this is built upon 20 layers of metajank and i despise it
 | 				d.uploaderJSON = user[0].toJSON(); // this is built upon 20 layers of metajank and i despise it
 | ||||||
| 				docs.push(d); | 				docs.push(d); | ||||||
| 			} | 			} | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
| 		// TODO: filter out _id and __v? possibly more
 | 		// TODO: filter out _id and __v? possibly more
 | ||||||
| 		res.send(docs); | 		res.send(docs); | ||||||
|  |  | ||||||
|  | @ -87,7 +87,7 @@ const FileSchema = new Schema({ | ||||||
| export const File = mongoose.model('File', FileSchema); | export const File = mongoose.model('File', FileSchema); | ||||||
| 
 | 
 | ||||||
| const UserSchema = new Schema({ // this is pretty much just a discord user lol
 | const UserSchema = new Schema({ // this is pretty much just a discord user lol
 | ||||||
| 	id: String, // discord id, cus longass number
 | 	id: {type: String, default: 'notgiven!!!!!!!!!!!!'}, // discord id, cus longass number
 | ||||||
| 	createdAt: Date, | 	createdAt: Date, | ||||||
| 
 | 
 | ||||||
| 	// caching
 | 	// caching
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue