Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix keepAlive parameter error #4194

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions apps/backend-mock/utils/jwt-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ import jwt from 'jsonwebtoken';

import { UserInfo } from './mock-data';

// TODO: Replace with your own secret key
const ACCESS_TOKEN_SECRET = 'access_token_secret';
const REFRESH_TOKEN_SECRET = 'refresh_token_secret';
Comment on lines +7 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security Concern: Avoid hardcoding secrets.

Hardcoding secrets like ACCESS_TOKEN_SECRET and REFRESH_TOKEN_SECRET poses a security risk. Consider using environment variables or a secure vault for managing secrets.

- const ACCESS_TOKEN_SECRET = 'access_token_secret';
- const REFRESH_TOKEN_SECRET = 'refresh_token_secret';
+ const ACCESS_TOKEN_SECRET = process.env.ACCESS_TOKEN_SECRET || 'default_access_token_secret';
+ const REFRESH_TOKEN_SECRET = process.env.REFRESH_TOKEN_SECRET || 'default_refresh_token_secret';
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// TODO: Replace with your own secret key
const ACCESS_TOKEN_SECRET = 'access_token_secret';
const REFRESH_TOKEN_SECRET = 'refresh_token_secret';
// TODO: Replace with your own secret key
const ACCESS_TOKEN_SECRET = process.env.ACCESS_TOKEN_SECRET || 'default_access_token_secret';
const REFRESH_TOKEN_SECRET = process.env.REFRESH_TOKEN_SECRET || 'default_refresh_token_secret';


export interface UserPayload extends UserInfo {
iat: number;
exp: number;
}

export function generateAccessToken(user: UserInfo) {
return jwt.sign(user, process.env.ACCESS_TOKEN_SECRET, { expiresIn: '2h' });
return jwt.sign(user, ACCESS_TOKEN_SECRET, { expiresIn: '2h' });
}

export function generateRefreshToken(user: UserInfo) {
return jwt.sign(user, process.env.REFRESH_TOKEN_SECRET, {
return jwt.sign(user, REFRESH_TOKEN_SECRET, {
expiresIn: '30d',
});
}
Expand All @@ -29,10 +33,7 @@ export function verifyAccessToken(

const token = authHeader.split(' ')[1];
try {
const decoded = jwt.verify(
token,
process.env.ACCESS_TOKEN_SECRET,
) as UserPayload;
const decoded = jwt.verify(token, ACCESS_TOKEN_SECRET) as UserPayload;

const username = decoded.username;
const user = MOCK_USERS.find((item) => item.username === username);
Expand All @@ -47,10 +48,7 @@ export function verifyRefreshToken(
token: string,
): null | Omit<UserInfo, 'password'> {
try {
const decoded = jwt.verify(
token,
process.env.REFRESH_TOKEN_SECRET,
) as UserPayload;
const decoded = jwt.verify(token, REFRESH_TOKEN_SECRET) as UserPayload;
const username = decoded.username;
const user = MOCK_USERS.find((item) => item.username === username);
const { password: _pwd, ...userinfo } = user;
Expand Down
12 changes: 11 additions & 1 deletion docs/src/guide/introduction/thin.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ apps/web-native

## Mock 服务精简

如果你不需要`Mock`服务,你可以直接删除`apps/backend-mock`文件夹即可。
如果你不需要`Mock`服务,你可以直接删除`apps/backend-mock`文件夹。同时在你的应用下`.env.development`文件中删除`VITE_NITRO_MOCK`变量。

```bash
# 是否开启 Nitro Mock服务,true 为开启,false 为关闭
VITE_NITRO_MOCK=false
```

## 安装依赖

Expand All @@ -47,6 +52,11 @@ pnpm install
```json
{
"scripts": {
"build:antd": "pnpm run build --filter=@vben/web-antd",
"build:docs": "pnpm run build --filter=@vben/docs",
"build:ele": "pnpm run build --filter=@vben/web-ele",
"build:naive": "pnpm run build --filter=@vben/web-naive",
"build:play": "pnpm run build --filter=@vben/playground",
"dev:antd": "pnpm -F @vben/web-antd run dev",
"dev:docs": "pnpm -F @vben/docs run dev",
"dev:ele": "pnpm -F @vben/web-ele run dev",
Expand Down
26 changes: 13 additions & 13 deletions packages/@core/base/design/src/design-tokens/dark/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

/* Used for destructive actions such as <Button variant="destructive"> */

--destructive: 0 78% 68%;
--destructive: 359.21 68.47% 56.47%;
--destructive-foreground: 0 0% 98%;

/* Used for success actions such as <message> */
Expand Down Expand Up @@ -110,7 +110,7 @@
--muted-foreground: 217.9 10.6% 64.9%;
--accent: 215 27.9% 16.9%;
--accent-foreground: 210 20% 98%;
--destructive: 0 62.8% 30.6%;
--destructive: 359.21 68.47% 56.47%;
--destructive-foreground: 210 20% 98%;
--border: 215 27.9% 16.9%;
--input: 215 27.9% 16.9%;
Expand All @@ -136,7 +136,7 @@
--muted-foreground: 240 5% 64.9%;
--accent: 12 6.5% 15.1%;
--accent-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive: 359.21 68.47% 56.47%;
--destructive-foreground: 0 85.7% 97.3%;
--border: 240 3.7% 15.9%;
--input: 240 3.7% 15.9%;
Expand All @@ -162,7 +162,7 @@
--muted-foreground: 0 0% 63.9%;
--accent: 0 0% 14.9%;
--accent-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive: 359.21 68.47% 56.47%;
--destructive-foreground: 0 0% 98%;
--border: 0 0% 14.9%;
--input: 0 0% 14.9%;
Expand All @@ -188,7 +188,7 @@
--muted-foreground: 215 20.2% 65.1%;
--accent: 217.2 32.6% 17.5%;
--accent-foreground: 210 40% 98%;
--destructive: 0 62.8% 30.6%;
--destructive: 359.21 68.47% 56.47%;
--destructive-foreground: 210 40% 98%;
--border: 217.2 32.6% 17.5%;
--input: 217.2 32.6% 17.5%;
Expand All @@ -214,7 +214,7 @@
--muted-foreground: 215 20.2% 65.1%;
--accent: 217.2 32.6% 17.5%;
--accent-foreground: 210 40% 98%;
--destructive: 0 62.8% 30.6%;
--destructive: 359.21 68.47% 56.47%;
--destructive-foreground: 210 40% 98%;
--border: 217.2 32.6% 17.5%;
--input: 217.2 32.6% 17.5%;
Expand All @@ -240,7 +240,7 @@
--muted-foreground: 240 5% 64.9%;
--accent: 12 6.5% 15.1%;
--accent-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive: 359.21 68.47% 56.47%;
--destructive-foreground: 0 85.7% 97.3%;
--border: 240 3.7% 15.9%;
--input: 240 3.7% 15.9%;
Expand All @@ -266,7 +266,7 @@
--muted-foreground: 240 5% 64.9%;
--accent: 12 6.5% 15.1%;
--accent-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive: 359.21 68.47% 56.47%;
--destructive-foreground: 0 85.7% 97.3%;
--border: 240 3.7% 15.9%;
--input: 240 3.7% 15.9%;
Expand Down Expand Up @@ -318,7 +318,7 @@
--muted-foreground: 24 5.4% 63.9%;
--accent: 12 6.5% 15.1%;
--accent-foreground: 60 9.1% 97.8%;
--destructive: 0 62.8% 30.6%;
--destructive: 359.21 68.47% 56.47%;
--destructive-foreground: 60 9.1% 97.8%;
--border: 12 6.5% 15.1%;
--input: 12 6.5% 15.1%;
Expand All @@ -344,7 +344,7 @@
--muted-foreground: 240 5% 64.9%;
--accent: 240 3.7% 15.9%;
--accent-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive: 359.21 68.47% 56.47%;
--destructive-foreground: 0 0% 98%;
--border: 240 3.7% 15.9%;
--input: 240 3.7% 15.9%;
Expand All @@ -370,7 +370,7 @@
--muted-foreground: 0 0% 63.9%;
--accent: 0 0% 14.9%;
--accent-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive: 359.21 68.47% 56.47%;
--destructive-foreground: 0 0% 98%;
--border: 0 0% 14.9%;
--input: 0 0% 14.9%;
Expand All @@ -396,7 +396,7 @@
--muted-foreground: 215 20.2% 65.1%;
--accent: 217.2 32.6% 17.5%;
--accent-foreground: 210 40% 98%;
--destructive: 0 62.8% 30.6%;
--destructive: 359.21 68.47% 56.47%;
--destructive-foreground: 210 40% 98%;
--border: 217.2 32.6% 17.5%;
--input: 217.2 32.6% 17.5%;
Expand All @@ -422,7 +422,7 @@
--muted-foreground: 217.9 10.6% 64.9%;
--accent: 215 27.9% 16.9%;
--accent-foreground: 210 20% 98%;
--destructive: 0 62.8% 30.6%;
--destructive: 359.21 68.47% 56.47%;
--destructive-foreground: 210 20% 98%;
--border: 215 27.9% 16.9%;
--input: 215 27.9% 16.9%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

/* Used for destructive actions such as <Button variant="destructive"> */

--destructive: 0 78% 68%;
--destructive: 359.33 100% 65.1%;
--destructive-foreground: 0 0% 98%;

/* Used for success actions such as <message> */
Expand Down
1 change: 1 addition & 0 deletions packages/@core/base/shared/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './inference';
export * from './letter';
export * from './merge';
export * from './nprogress';
export * from './to';
export * from './tree';
export * from './unique';
export * from './update-css-variables';
Expand Down
21 changes: 21 additions & 0 deletions packages/@core/base/shared/src/utils/to.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @param { Readonly<Promise> } promise
* @param {object=} errorExt - Additional Information you can pass to the err object
* @return { Promise }
*/
export async function to<T, U = Error>(
promise: Readonly<Promise<T>>,
errorExt?: object,
): Promise<[null, T] | [U, undefined]> {
try {
const data = await promise;
const result: [null, T] = [null, data];
return result;
} catch (error) {
if (errorExt) {
const parsedError = Object.assign({}, error, errorExt);
return [parsedError as U, undefined];
}
return [error as U, undefined];
}
}
Comment on lines +1 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New utility function to is well-implemented.

This utility function provides a clean way to handle promises with error extensions. Consider adding unit tests to ensure its reliability.

Would you like me to generate unit tests for this utility function or open a GitHub issue to track this task?

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
import type { CSSProperties } from 'vue';
import { computed, useSlots } from 'vue';

import { Menu } from '@vben-core/icons';
import { VbenIconButton } from '@vben-core/shadcn-ui';

interface Props {
/**
* 横屏
Expand All @@ -14,11 +11,6 @@ interface Props {
* 高度
*/
height: number;
/**
* 是否混合导航
* @default false
*/
isMixedNav: boolean;
/**
* 是否移动端
*/
Expand All @@ -27,11 +19,6 @@ interface Props {
* 是否显示
*/
show: boolean;
/**
* 是否显示关闭菜单按钮
*/
showToggleBtn: boolean;

/**
* 侧边菜单宽度
*/
Expand All @@ -52,8 +39,6 @@ interface Props {

const props = withDefaults(defineProps<Props>(), {});

const emit = defineEmits<{ openMenu: []; toggleSidebar: [] }>();

const slots = useSlots();

const style = computed((): CSSProperties => {
Expand All @@ -72,10 +57,6 @@ const logoStyle = computed((): CSSProperties => {
minWidth: `${props.isMobile ? 40 : props.sidebarWidth}px`,
};
});

function handleToggleMenu() {
props.isMobile ? emit('openMenu') : emit('toggleSidebar');
}
</script>

<template>
Expand All @@ -87,13 +68,9 @@ function handleToggleMenu() {
<div v-if="slots.logo" :style="logoStyle">
<slot name="logo"></slot>
</div>
<VbenIconButton
v-if="showToggleBtn || isMobile"
class="my-0 ml-2 mr-1 rounded-md"
@click="handleToggleMenu"
>
<Menu class="size-4" />
</VbenIconButton>

<slot name="toggle-button"> </slot>

<slot></slot>
</header>
</template>
41 changes: 29 additions & 12 deletions packages/@core/ui-kit/layout-ui/src/vben-layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import type { VbenLayoutProps } from './vben-layout';
import type { CSSProperties } from 'vue';
import { computed, ref, watch } from 'vue';

import { Menu } from '@vben-core/icons';
import { VbenIconButton } from '@vben-core/shadcn-ui';

import { useMouse, useScroll, useThrottleFn } from '@vueuse/core';

import {
Expand Down Expand Up @@ -330,11 +333,12 @@ const maskStyle = computed((): CSSProperties => {

const showHeaderToggleButton = computed(() => {
return (
props.headerToggleSidebarButton &&
isSideMode.value &&
!isSidebarMixedNav.value &&
!isMixedNav.value &&
!props.isMobile
props.isMobile ||
(props.headerToggleSidebarButton &&
isSideMode.value &&
!isSidebarMixedNav.value &&
!isMixedNav.value &&
!props.isMobile)
);
});

Expand Down Expand Up @@ -421,8 +425,12 @@ function handleClickMask() {
sidebarCollapse.value = true;
}

function handleOpenMenu() {
sidebarCollapse.value = false;
function handleHeaderToggle() {
if (props.isMobile) {
sidebarCollapse.value = false;
} else {
emit('toggleSidebar');
}
}
</script>

Expand Down Expand Up @@ -473,27 +481,36 @@ function handleOpenMenu() {
class="flex flex-1 flex-col overflow-hidden transition-all duration-300 ease-in"
>
<div
:class="{
'shadow-[0_16px_24px_hsl(var(--background))]': scrollY > 20,
}"
:style="headerWrapperStyle"
class="overflow-hidden shadow-[0_16px_24px_hsl(var(--background))] transition-all duration-200"
class="overflow-hidden transition-all duration-200"
>
<LayoutHeader
v-if="headerVisible"
:full-width="!isSideMode"
:height="headerHeight"
:is-mixed-nav="isMixedNav"
:is-mobile="isMobile"
:show="!isFullContent && !headerHidden"
:show-toggle-btn="showHeaderToggleButton"
:sidebar-width="sidebarWidth"
:theme="headerTheme"
:width="mainStyle.width"
:z-index="headerZIndex"
@open-menu="handleOpenMenu"
@toggle-sidebar="() => emit('toggleSidebar')"
>
<template v-if="showHeaderLogo" #logo>
<slot name="logo"></slot>
</template>

<template #toggle-button>
<VbenIconButton
v-if="showHeaderToggleButton"
class="my-0 ml-2 mr-1 rounded-md"
@click="handleHeaderToggle"
>
<Menu class="size-4" />
</VbenIconButton>
</template>
<slot name="header"></slot>
</LayoutHeader>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import type { MenuItemProps, MenuItemRegistered } from '../interface';
import type { MenuItemProps, MenuItemRegistered } from '../types';

import { computed, onBeforeUnmount, onMounted, reactive, useSlots } from 'vue';

Expand Down
Loading
Loading