-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #580 from douglasnaphas/v2-login
Allow link retrieval by the leader, remove v1 flow
- Loading branch information
Showing
28 changed files
with
1,041 additions
and
598 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
const { | ||
DynamoDBDocumentClient, | ||
QueryCommand, | ||
} = require("@aws-sdk/lib-dynamodb"); | ||
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb"); | ||
const schema = require("../schema"); | ||
const dynamoDBClient = new DynamoDBClient({}); | ||
const docClient = DynamoDBDocumentClient.from(dynamoDBClient); | ||
const mySeders = () => [ | ||
// 401 if no login cookie | ||
(req, res, next) => { | ||
if (!req.cookies.login) { | ||
return res.status(401).send({ err: "unauthenticated" }); | ||
} | ||
return next(); | ||
}, | ||
// Get the cookie from the db, note the user email | ||
async (req, res, next) => { | ||
const getCookieQueryCommand = new QueryCommand({ | ||
TableName: schema.TABLE_NAME, | ||
IndexName: schema.OPAQUE_COOKIE_INDEX, | ||
KeyConditionExpression: `#OC = :oc`, | ||
ExpressionAttributeNames: { "#OC": schema.OPAQUE_COOKIE }, | ||
ExpressionAttributeValues: { ":oc": req.cookies.login }, | ||
}); | ||
const getCookieQueryResponse = await docClient.send(getCookieQueryCommand); | ||
if ( | ||
!getCookieQueryResponse || | ||
!getCookieQueryResponse.Items || | ||
!getCookieQueryResponse.Items[0] | ||
) { | ||
console.log( | ||
"problem getting user nickname and email, getCookieQueryResponse", | ||
getCookieQueryResponse | ||
); | ||
return res.status(401).send({ err: "unauthenticated" }); | ||
} | ||
const { user_nickname, user_email } = getCookieQueryResponse.Items[0]; | ||
res.locals.user_email = user_email; | ||
return next(); | ||
}, | ||
// Get the seders the user started | ||
async (req, res, next) => { | ||
const getMySedersQueryCommand = new QueryCommand({ | ||
TableName: schema.TABLE_NAME, | ||
IndexName: schema.LEADER_EMAIL_INDEX, | ||
KeyConditionExpression: `#LE = :le`, | ||
ExpressionAttributeNames: { "#LE": schema.LEADER_EMAIL }, | ||
ExpressionAttributeValues: { ":le": res.locals.user_email }, | ||
}); | ||
const getMySedersQueryResponse = await docClient.send( | ||
getMySedersQueryCommand | ||
); | ||
if (!getMySedersQueryResponse) { | ||
console.log( | ||
"problem getting leader's seders, getMySedersQueryResponse", | ||
getMySedersQueryResponse | ||
); | ||
return res.status(500).send({ err: "server error" }); | ||
} | ||
if ( | ||
!getMySedersQueryResponse.Items || | ||
!Array.isArray(getMySedersQueryResponse.Items) | ||
) { | ||
return res.send([]); | ||
} | ||
try { | ||
res.locals.mySeders = getMySedersQueryResponse.Items.filter( | ||
(item) => item.lib_id === schema.SEDER_PREFIX | ||
).map((item) => { | ||
return { | ||
room_code: item.room_code, | ||
created: item.created, | ||
pw: item.pw, | ||
timestamp: item.timestamp, | ||
}; | ||
}); | ||
} catch (err) { | ||
console.log( | ||
"my-seders: problem getting seders from query response", | ||
res.locals.user_email | ||
); | ||
console.log(err); | ||
return res.status(500).send({ err: "server error" }); | ||
} | ||
return res.send(res.locals.mySeders); | ||
}, | ||
]; | ||
module.exports = mySeders; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const { | ||
DynamoDBDocumentClient, | ||
QueryCommand, | ||
} = require("@aws-sdk/lib-dynamodb"); | ||
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb"); | ||
const schema = require("../schema"); | ||
const dynamoDBClient = new DynamoDBClient({}); | ||
const docClient = DynamoDBDocumentClient.from(dynamoDBClient); | ||
const user = () => [ | ||
// 401 if no login cookie | ||
(req, res, next) => { | ||
if (!req.cookies.login) { | ||
return res.status(401).send({ err: "unauthenticated" }); | ||
} | ||
return next(); | ||
}, | ||
// Get the cookie from the db | ||
async (req, res, next) => { | ||
const getCookieQueryCommand = new QueryCommand({ | ||
TableName: schema.TABLE_NAME, | ||
IndexName: schema.OPAQUE_COOKIE_INDEX, | ||
KeyConditionExpression: `#OC = :oc`, | ||
ExpressionAttributeNames: { "#OC": schema.OPAQUE_COOKIE }, | ||
ExpressionAttributeValues: { ":oc": req.cookies.login }, | ||
}); | ||
const getCookieQueryResponse = await docClient.send(getCookieQueryCommand); | ||
if ( | ||
!getCookieQueryResponse || | ||
!getCookieQueryResponse.Items || | ||
!getCookieQueryResponse.Items[0] | ||
) { | ||
console.log( | ||
"problem getting user nickname and email, getCookieQueryResponse", | ||
getCookieQueryResponse | ||
); | ||
return res.status(401).send({ err: "unauthenticated" }); | ||
} | ||
const { user_nickname, user_email } = getCookieQueryResponse.Items[0]; | ||
return res.send({ user_nickname, user_email }); | ||
}, | ||
]; | ||
module.exports = user; |
Oops, something went wrong.