Skip to content

Commit

Permalink
fix: default skin
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi1520 committed Jul 5, 2021
1 parent 6c7b53e commit c862ff3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
4 changes: 4 additions & 0 deletions public/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var skin = localStorage.getItem('skin');
if (skin) {
document.documentElement.classList.add(skin);
}
5 changes: 1 addition & 4 deletions server/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ authRouter.post('/signin', async (req, res) => {
//检查密码是否匹配
const pwdMatchFlag = bcrypt.compareSync(password, user.password);
if (pwdMatchFlag) {
const token = jwt.sign(
{ ...user, password: undefined },
process.env.JWT_SECRET
);
const token = jwt.sign({ id: user.id }, process.env.JWT_SECRET);
res.cookie('token', token, { httpOnly: true });
res.json({
token: token,
Expand Down
9 changes: 7 additions & 2 deletions server/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import jwt from 'jsonwebtoken';
import prisma from '../prisma';

export interface Req extends Request {
user: User;
user: Omit<User, 'password'>;
}

export async function protect(
Expand All @@ -21,9 +21,14 @@ export async function protect(

try {
const token = req.cookies.token;
const decoded = jwt.verify(token, process.env.JWT_SECRET) as User;
const decoded = jwt.verify(token, process.env.JWT_SECRET) as { id: number };
if (decoded.id) {
const user = await prisma.user.findUnique({
select: {
id: true,
name: true,
email: true,
},
where: {
id: decoded.id,
},
Expand Down
6 changes: 0 additions & 6 deletions src/components/Header/Base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Icon from '../Icon';
interface Props {
children: ReactElement;
}

export default function Header({ children }: Props): ReactElement {
const { user } = useMe();
const [current, setCurrent] = useState('');
Expand All @@ -22,11 +21,6 @@ export default function Header({ children }: Props): ReactElement {
const skin = localStorage.getItem('skin');
if (skin) {
setCurrent(skin);
document.documentElement.classList.add(skin);
} else {
document.documentElement.classList.add('theme-light');
localStorage.setItem('skin', 'theme-light');
setCurrent(skin);
}
}, []);
return (
Expand Down
2 changes: 2 additions & 0 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @next/next/no-sync-scripts */
import Document, { Html, Head, Main, NextScript } from 'next/document';
import { description, keywords } from '../config';

Expand All @@ -14,6 +15,7 @@ class MyDocument extends Document {
<meta name="description" content={description} />
<meta name="keywords" content={keywords} />
<link rel="icon" href="/favicon.ico" />
<script type="text/javascript" src="/theme.js"></script>
</Head>
<body className="text-skin-base transition-colors bg-skin-base text-sm">
<Main />
Expand Down

1 comment on commit c862ff3

@vercel
Copy link

@vercel vercel bot commented on c862ff3 Jul 5, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.