本文整理汇总了TypeScript中feathers-hooks-common.disallow函数的典型用法代码示例。如果您正苦于以下问题:TypeScript disallow函数的具体用法?TypeScript disallow怎么用?TypeScript disallow使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了disallow函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: disallow
const disallowExternal = (hook: BeforeHookContext<DefaultDocument>) => {
if (hook.path === 'authentication') {
return hook;
}
return disallow('external')(hook);
};
示例2: debug
import validateInSteamGroup from './validate-in-steam-group';
import validateHours from './validate-hours';
const log = debug('TF2Pickup:users:hooks');
const inviteUserToGroup = promisify(steamCommunity.inviteUserToGroup.bind(steamCommunity));
const hooks: Hooks<User> = {
before: {
create: [
// Validate that the userId is in the steam group when the website is in beta mode
validateInSteamGroup,
// Validate the users TF2 hours
validateHours,
],
remove: disallow(),
},
after: {
create: [
(hook) => {
log('Created a new user', {
userId: hook.result.id,
data: hook.result,
});
},
// Create the rest of the documents for a userId.
async (hook: CreateAfterHookContext<User>) => {
await hook.app.service('user-settings').create({
id: hook.result.id,
volume: 0.7,
示例3: requireAuth
function requireAuth(
hook: BeforeHookContext<DefaultDocument>
) {
if (hook.params.provider === 'external') {
return auth.hooks.authenticate(['jwt'])(hook);
}
return hook;
}
const hooks: Hooks<DefaultDocument> = {
before: {
find: requireAuth,
get: requireAuth,
// Completely disallow the update hook
update: disallow(),
// Disallow every patch, remove, create call from external
patch: disallowExternal,
remove: disallowExternal,
create: disallowExternal,
},
error: {
all(hook) {
if (hook.error.code === 404) {
return hook;
}
log(
`Error in '${hook.path}' service method ${hook.method.toUpperCase()}`,
{ error: hook.error },
示例4: create
import { CreateBeforeHookContext } from '@feathersjs/feathers';
import hooks from 'feathers-hooks-common';
import UserProfile from '@typings/UserProfile';
import getUserData from './get-user-data';
export default {
before: {
find: hooks.disallow(),
remove: hooks.disallow(),
async create(hook: CreateBeforeHookContext<UserProfile>) {
const data = await getUserData(hook.data);
return {
...hook,
data: {
...hook.data,
...data,
},
};
},
},
};