mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
refactor : improving code clarity and removing unnecessary else
This commit is contained in:
@@ -34,27 +34,24 @@ const _checkAuth = async (
|
||||
response: http.ServerResponse,
|
||||
callback: (response: http.OutgoingMessage, workspace: string) => boolean
|
||||
) => {
|
||||
const url = new URL(request.url, `http://${request.headers.host}`);
|
||||
const workspace = _getWorkspace(url.pathname);
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
const url = new URL(request.url, `http://${request.headers.host}`);
|
||||
const workspace = _getWorkspace(url.pathname);
|
||||
if (workspace) return callback(response, workspace);
|
||||
return false;
|
||||
} else {
|
||||
try {
|
||||
const decodedToken = await firebaseAuth
|
||||
.getAuth()
|
||||
.verifyIdToken(request.headers.token as string);
|
||||
const allowWorkspace = [AFFINE_COMMON_WORKSPACE, decodedToken.uid];
|
||||
const url = new URL(request.url, `http://${request.headers.host}`);
|
||||
const workspace = _getWorkspace(url.pathname);
|
||||
if (allowWorkspace.includes(workspace)) {
|
||||
return callback(response, workspace);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
const decodedToken = await firebaseAuth
|
||||
.getAuth()
|
||||
.verifyIdToken(request.headers.token as string);
|
||||
const allowWorkspace = [AFFINE_COMMON_WORKSPACE, decodedToken.uid];
|
||||
if (allowWorkspace.includes(workspace)) {
|
||||
return callback(response, workspace);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const HOST = process.env.HOST || 'localhost';
|
||||
|
||||
Reference in New Issue
Block a user