1
0
Fork 0
mirror of synced 2024-07-02 21:10:43 +12:00

codereview: looksLikeAppId as variable

This commit is contained in:
Michael Shanks 2020-06-19 17:21:24 +01:00
parent 4ba1329983
commit 31f8d3bee2

View file

@ -26,7 +26,8 @@ exports.serveApp = async function(ctx) {
) )
// only set the appId cookie for /appId .. we COULD check for valid appIds // only set the appId cookie for /appId .. we COULD check for valid appIds
// but would like to avoid that DB hit // but would like to avoid that DB hit
if (looksLikeAppId(ctx.params.appId) && !ctx.isAuthenticated) { const looksLikeAppId = /^[0-9a-f]{32}$/.test(ctx.params.appId)
if (looksLikeAppId && !ctx.isAuthenticated) {
const anonUser = { const anonUser = {
userId: "ANON", userId: "ANON",
accessLevelId: ANON_LEVEL_ID, accessLevelId: ANON_LEVEL_ID,
@ -74,5 +75,3 @@ exports.serveComponentLibrary = async function(ctx) {
await send(ctx, "/index.js", { root: componentLibraryPath }) await send(ctx, "/index.js", { root: componentLibraryPath })
} }
const looksLikeAppId = appId => /^[0-9a-f]{32}$/.test(appId)