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});
|
||||
let userUuid = '';
|
||||
|
||||
if (users.length === 0) {
|
||||
const newUser = new User({
|
||||
id: userInfo.id,
|
||||
id: String(userInfo.data.id),
|
||||
createdAt: new Date(),
|
||||
|
||||
username: userInfo.data.username,
|
||||
|
@ -50,12 +51,18 @@ export function run(app) {
|
|||
userUuid = newUser.get('uuid');
|
||||
newUser.save();
|
||||
} 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!.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) {
|
||||
res.send(`whoooops<br>${err}`);
|
||||
console.error(err);
|
||||
|
|
|
@ -85,8 +85,10 @@ db.then(() => {
|
|||
for (const doc of files) {
|
||||
const d = doc.toJSON();
|
||||
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
|
||||
docs.push(d);
|
||||
if (user) {
|
||||
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
|
||||
|
|
|
@ -87,7 +87,7 @@ const FileSchema = new Schema({
|
|||
export const File = mongoose.model('File', FileSchema);
|
||||
|
||||
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,
|
||||
|
||||
// caching
|
||||
|
|
Loading…
Reference in a new issue