Skip to content

Commit

Permalink
Merge branch 'dev' into analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Nov 16, 2022
2 parents f0a072c + 592c3fa commit 94848cc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion db/clickhouse/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ SELECT website_id,
language,
country,
event_name,
event_data,
if((empty(event_data) = 0) AND startsWith(event_data, '"'), concat('{', event_data, ': true}'), event_data) AS event_data,
created_at
FROM event_queue;
11 changes: 4 additions & 7 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,21 @@ export function isValidToken(token, validation) {
export async function allowQuery(req, type) {
const { id } = req.query;

const {
user: { id: userId, isAdmin },
shareToken,
} = req.auth;
const { user, shareToken } = req.auth;

if (isAdmin) {
if (user?.isAdmin) {
return true;
}

if (shareToken) {
return isValidToken(shareToken, { id });
}

if (userId) {
if (user?.id) {
if (type === TYPE_WEBSITE) {
const website = await getWebsite({ id });

return website && website.userId === userId;
return website && website.userId === user.id;
} else if (type === TYPE_USER) {
const user = await getUser({ id });

Expand Down
4 changes: 2 additions & 2 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ export const useAuth = createMiddleware(async (req, res, next) => {
const payload = parseSecureToken(token, secret());
const shareToken = await parseShareToken(req);

let user;
let user = null;
const { userId, key } = payload || {};

if (validate(userId)) {
user = await getUser({ id: userId });
} else if (redis.enabled) {
} else if (redis.enabled && key) {
user = await redis.get(key);
}

Expand Down

0 comments on commit 94848cc

Please sign in to comment.