-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Title: Resolved issue with Beacon leader being null #375
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,12 +36,20 @@ const resolvers = { | |
return beacon; | ||
}, | ||
group: async (_parent, { id }, { user }) => { | ||
const group = await Group.findById(id).populate("leader members beacons"); | ||
if (!group) return new UserInputError("No group exists with that id."); | ||
// return error iff user not in group | ||
if (group.leader.id !== user.id && !group.members.includes(user)) | ||
return new Error("User should be a part of the group"); | ||
return group; | ||
const group = await Group.findById(id).populate('leader members').populate({ | ||
path: 'beacons', | ||
populate: { | ||
path: 'leader', | ||
}, | ||
}); | ||
|
||
if (!group) return new UserInputError("No group exists with that id."); | ||
// Check if the user is part of the group | ||
if (group.leader.id !== user.id && !group.members.includes(user)) | ||
throw new Error("User should be a part of the group"); | ||
|
||
console.log(`group: ${group}`); | ||
return group; | ||
}, | ||
nearbyBeacons: async (_, { location }) => { | ||
// get active beacons | ||
|
@@ -73,10 +81,39 @@ const resolvers = { | |
password: await bcrypt.hash(credentials.password, 10), | ||
}), | ||
}); | ||
console.log(newUser); | ||
const userObj = await newUser.save(); | ||
return userObj; | ||
}, | ||
|
||
oAuth: async (_parent, { userInput }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using this function for google and oAuth signup, userInput will come from frontend through flutter libraries and then some operations are performed. for oAuth i have created this Closes #373 |
||
|
||
const { name, email } = userInput; | ||
let user = await User.findOne({ email }); | ||
|
||
if (!user) { | ||
const newUser = new User({ name, email }); | ||
user = await newUser.save(); | ||
} | ||
|
||
const anon = false; | ||
const tokenPayload = { | ||
"https://beacon.ccextractor.org": { | ||
anon, | ||
...(email && { email }), | ||
}, | ||
}; | ||
|
||
const token = jwt.sign(tokenPayload, process.env.JWT_SECRET, { | ||
algorithm: "HS256", | ||
subject: user._id.toString(), | ||
expiresIn: "7d", | ||
}); | ||
|
||
return token; | ||
}, | ||
|
||
|
||
login: async (_parent, { id, credentials }) => { | ||
if (!id && !credentials) return new UserInputError("One of ID and credentials required"); | ||
|
||
|
@@ -93,11 +130,10 @@ const resolvers = { | |
let anon = true; | ||
|
||
if (credentials) { | ||
const valid = email === user.email && (await bcrypt.compare(password, user.password)); | ||
const valid = (email === user.email && bcrypt.compare(password, user.password)); | ||
if (!valid) return new AuthenticationError("credentials don't match"); | ||
anon = false; | ||
} | ||
|
||
return jwt.sign( | ||
{ | ||
"https://beacon.ccextractor.org": { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, need to review the rest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @aadibajpai, I'm actively addressing the issue. Additionally, I'm proposing a new feature that allows leaders to toggle between displaying their name or remaining anonymous on the beacon. So i want to close this pr for now soon i'll complete proposed feature and create a new pr.