Fixed share page issue.
This commit is contained in:
14
lib/auth.js
14
lib/auth.js
@@ -15,7 +15,7 @@ export function getAuthToken(req) {
|
||||
|
||||
export function getShareToken(req) {
|
||||
try {
|
||||
return parseSecureToken(req.headers[SHARE_TOKEN_HEADER], secret());
|
||||
return parseToken(req.headers[SHARE_TOKEN_HEADER], secret());
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
@@ -23,12 +23,10 @@ export function getShareToken(req) {
|
||||
|
||||
export function isValidToken(token, validation) {
|
||||
try {
|
||||
const result = parseToken(token, secret());
|
||||
|
||||
if (typeof validation === 'object') {
|
||||
return !Object.keys(validation).find(key => result[key] !== validation[key]);
|
||||
return !Object.keys(validation).find(key => token[key] !== validation[key]);
|
||||
} else if (typeof validation === 'function') {
|
||||
return validation(result);
|
||||
return validation(token);
|
||||
}
|
||||
} catch (e) {
|
||||
return false;
|
||||
@@ -38,7 +36,7 @@ export function isValidToken(token, validation) {
|
||||
}
|
||||
|
||||
export async function allowQuery(req) {
|
||||
const { id: websiteId } = req.query;
|
||||
const { id } = req.query;
|
||||
|
||||
const { userId, isAdmin, shareToken } = req.auth ?? {};
|
||||
|
||||
@@ -47,11 +45,11 @@ export async function allowQuery(req) {
|
||||
}
|
||||
|
||||
if (shareToken) {
|
||||
return isValidToken(shareToken, { websiteUuid: websiteId });
|
||||
return isValidToken(shareToken, { id });
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
const website = await getWebsite({ websiteUuid: websiteId });
|
||||
const website = await getWebsite({ id });
|
||||
|
||||
return website && website.userId === userId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user