Merge pull request #127 from CarlosZoft/refactor/apply-good-practices
Refactor : applyed good practices
This commit is contained in:
@@ -34,34 +34,31 @@ const _checkAuth = async (
|
|||||||
response: http.ServerResponse,
|
response: http.ServerResponse,
|
||||||
callback: (response: http.OutgoingMessage, workspace: string) => boolean
|
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') {
|
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);
|
if (workspace) return callback(response, workspace);
|
||||||
return false;
|
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';
|
const HOST = process.env.HOST || 'localhost';
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
|
|
||||||
const _tokens = new LRUCache<string, string>({
|
const _tokens = new LRUCache<string, string>({
|
||||||
max: 10240,
|
max: 1024 * 10,
|
||||||
ttl: 1000 * 60 * 5,
|
ttl: 1000 * 60 * 5,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -10,16 +10,13 @@ export function WorkspaceHome() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const navigate_to_user_initial_page = async () => {
|
const navigate_to_user_initial_page = async () => {
|
||||||
const recent_pages = await services.api.userConfig.getRecentPages(
|
const [recent_pages, user_initial_page_id] = await Promise.all([
|
||||||
workspace_id,
|
services.api.userConfig.getRecentPages(workspace_id, user.id),
|
||||||
user.id
|
services.api.userConfig.getUserInitialPage(
|
||||||
);
|
|
||||||
|
|
||||||
const user_initial_page_id =
|
|
||||||
await services.api.userConfig.getUserInitialPage(
|
|
||||||
workspace_id,
|
workspace_id,
|
||||||
user.id
|
user.id
|
||||||
);
|
),
|
||||||
|
]);
|
||||||
if (recent_pages.length === 0) {
|
if (recent_pages.length === 0) {
|
||||||
await services.api.editorBlock.copyTemplateToPage(
|
await services.api.editorBlock.copyTemplateToPage(
|
||||||
workspace_id,
|
workspace_id,
|
||||||
|
|||||||
@@ -95,15 +95,11 @@ export const WorkspaceName = () => {
|
|||||||
if (!currentSpaceId) {
|
if (!currentSpaceId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const [name, workspaceId] = await Promise.all([
|
||||||
const name = await services.api.userConfig.getWorkspaceName(
|
services.api.userConfig.getWorkspaceName(currentSpaceId),
|
||||||
currentSpaceId
|
services.api.userConfig.getWorkspaceId(currentSpaceId),
|
||||||
);
|
]);
|
||||||
setWorkspaceName(name);
|
setWorkspaceName(name);
|
||||||
|
|
||||||
const workspaceId = await services.api.userConfig.getWorkspaceId(
|
|
||||||
currentSpaceId
|
|
||||||
);
|
|
||||||
setWorkspaceId(workspaceId);
|
setWorkspaceId(workspaceId);
|
||||||
}, [currentSpaceId]);
|
}, [currentSpaceId]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user