Q: 关于 hook || Q: About hooks #2096
Replies: 1 comment 10 replies
-
// index.js
const Waline = require('@waline/vercel');
module.exports = Waline({
plugins: [
{
middlewares: [
async (ctx, next) => {
if(ctx.method !== 'POST' || ctx.url !== '/api/user') {
return next();
}
const { storage } = think.config();
const userModel = ctx.services(`storage/${storage}`, 'Users');
const { display_name } = ctx.post();
const users = await userModel.where({ display_name }).select();
if (think.isEmpty(users)) {
ctx.status = 500;
return ctx.fail('昵称被占用');
}
await next();
},
],
},
],
}); |
Beta Was this translation helpful? Give feedback.
10 replies
Answer selected by
felixesintot
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the bug | 问题描述
想实现两个简单的功能:要求评论的昵称和邮箱不为空以及注册用户的昵称不能与他人一样
但不是很懂 hook 怎么写,有没有大佬教教我
Website URL | 问题网站
https://waline.felixesintot.top
Where your waline deploy? | 服务部署在哪里?
Vercel (Default)
Where your comment data store? | 数据存储在哪里?
LeanCloud(https://leancloud.app)
Describe the bug | Problem description
I want to implement two simple functions: the nickname and email address of the comment must not be empty, and the nickname of the registered user cannot be the same as others.
But I don’t know how to write hook. Can anyone teach me?
Website URL | Problem website
https://waline.felixesintot.top
Where your waline deploy? | Where is the service deployed?
Vercel (Default)
Where your comment data store? | Where is the data stored?
LeanCloud(https://leancloud.app)
Beta Was this translation helpful? Give feedback.
All reactions