fixed a few issues with auth

This commit is contained in:
oat 2020-10-12 17:10:18 +03:00
parent 96facbf2e2
commit f113c472fd
Signed by: oat
GPG key ID: DD83A9617A252385
3 changed files with 15 additions and 6 deletions

View file

@ -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);

View file

@ -85,8 +85,10 @@ 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});
d.uploaderJSON = user[0].toJSON(); // this is built upon 20 layers of metajank and i despise it if (user) {
docs.push(d); d.uploaderJSON = user[0].toJSON(); // this is built upon 20 layers of metajank and i despise it
docs.push(d);
}
} }
// TODO: filter out _id and __v? possibly more // TODO: filter out _id and __v? possibly more

View file

@ -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