Sails.js无法访问中间件中的数据模型:意外的令牌

时间:2018-04-06 13:50:50

标签: sails.js

sails.js新手在这里。

我无法访问我的中间件中的Function Update-GroupOwnershipAttributes() { <# .Synopsis Allows updating of ManagedBy & extensionAttributes 1-4 for an Active Directory group .EXAMPLE Update-GroupOwnershipAttributes -Identity someGroupName -ManagedBy someManager -Ext1 - .EXAMPLE .INPUTS .OUTPUTS .NOTES .COMPONENT .ROLE .FUNCTIONALITY #> [cmdletBinding()] param( [Parameter(Mandatory=$True, Position=0, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)] [ValidateNotNull()] [ValidateNotNullOrEmpty()] [ValidateScript( { if($(Test-Group $_) -eq $True) { $True } else { throw "Group $_ not found" } } )] [String]$Identity, [Parameter(Mandatory=$False)] [ValidateNotNull()] [ValidateNotNullOrEmpty()] [ValidateScript({ if($(Test-User $_) -eq $True) { $True } else { throw "User $_ not found" $False } })] [String]$ManagedBy, [Parameter(Mandatory=$False)] [ValidateSet("SomeValueICareAbout")] [String]$Ext1, [Parameter(Mandatory=$False)] [ValidateSet("True","False")] [String]$Ext2, [Parameter(Mandatory=$False, Position=3)] [ValidateScript( { if($(Test-User $_) -eq $True) { $True } else { throw "User $_ not found" $False } })] [String]$Ext3, [Parameter(Mandatory=$False, Position=4)] [ValidateScript( { if($(Test-User $_) -eq $True) { $True } else { throw "User $_ not found" $False } })] [String]$Ext4 ) BEGIN {} PROCESS { # Set arguments so we don't have to have # dozens of if/elseif statements $params = else { } # All params if($ManagedBy -ne $null -and $Ext1 -and $Ext2 -and $Ext3 -and $Ext4) { try { #Set-ADGroup -Identity $Identity -ManagedBy $ManagedBy -Replace @{extensionAttribute1=$Ext1;extensionAttribute2=$Ext2;extensionAttribute3=$Ext3;extensionAttribute4=$Ext4} } catch [Exception] { } } # All except Ext1 elseif($ManagedBy -ne $null -and $Ext2 -and $Ext3 -and $Ext4) { try { #Set-ADGroup -Identity $Identity -ManagedBy $ManagedBy -Replace @{extensionAttribute2=$Ext2;extensionAttribute3=$Ext3;extensionAttribute4=$Ext4} } catch [Exception] { } } # All except Ext2 elseif($ManagedBy -ne $null -and $Ext1 -and $Ext3 -and $Ext4) { try { #Set-ADGroup -Identity $Identity -ManagedBy $ManagedBy -Replace @{extensionAttribute1=$Ext1;extensionAttribute3=$Ext3;extensionAttribute4=$Ext4} } catch [Exception] { } } # All except Ext3 elseif($ManagedBy -ne $null -and $Ext1 -and $Ext2 -and $Ext4) { try { #Set-ADGroup -Identity $Identity -ManagedBy $ManagedBy -Replace @{extensionAttribute1=$Ext1;extensionAttribute2=$Ext2;extensionAttribute4=$Ext4} } catch [Exception] { } } # All except Ext4 elseif($ManagedBy -ne $null -and $Ext1 -and $Ext2 -and $Ext3) { try { #Set-ADGroup -Identity $Identity -ManagedBy $ManagedBy -Replace @{extensionAttribute1=$Ext1;extensionAttribute2=$Ext2;extensionAttribute4=$Ext3} } catch [Exception] { } } # All except ManagedBy elseif($ManagedBy -eq $null -and $Ext1 -and $Ext2 -and $Ext3 -and $Ext4) { try { #Set-ADGroup -Identity $Identity -Replace @{extensionAttribute1=$Ext1;extensionAttribute2=$Ext2;extensionAttribute4=$Ext3} } catch [Exception] { } } } END {} } 模型。它说意外的令牌。

这是我的中间件,

User

我正在尝试设置身份验证中间件。在我的全局设置中, isAuthenticated: (function(){ return function authHandler(req, res, next) { let payload; try { payload = decode(req); let expTime = moment.tz(payload.exp, 'GMT').toDate(); let currentTIme = moment.tz('GMT').toDate(); if (currentTIme > expTime) { return res.status(401).json({message: 'JWT token expired.'}); } else { >> const user = await User.findOne({id: payload.id}); if (user) { req.payload = { userId: user.id }; return next() } else { return res.status(401).json({message: 'User doesn\'t exist.'}); } } } catch (err) { return res.serverError(); } } })() } 设置为models

我试过了,true但即便如此,我也会得到意想不到的令牌。

1 个答案:

答案 0 :(得分:1)

您需要设置async关键字async function(..){....await....}await关键字仅在异步函数中有效。