我有一個feathters.js應用程序,現在我想確保創建和更新掛鉤。我使用一個socket.io客戶端,目前正在爲智威湯遜。我已經添加了我認爲我需要添加的內容,但是獲得了Error: Authentication token missing
和Error Authenticating
。我後來知道這是來自我的代碼。我有一個後端/前端的情況feathers.js - >身份驗證令牌丟失
所以這就是我到目前爲止所實現的。
文件:後端\ backend.js(稱爲後端\ index.js用於該應用程序的配置)
'use strict';
const path = require('path');
const serveStatic = require('feathers').static;
const favicon = require('serve-favicon');
const compress = require('compression');
const cors = require('cors');
const feathers = require('feathers');
const configuration = require('feathers-configuration');
const authentication = require('feathers-authentication');
const hooks = require('feathers-hooks');
const rest = require('feathers-rest');
const bodyParser = require('body-parser');
const socketio = require('feathers-socketio');
const middleware = require('./middleware/index');
const services = require('./services/index');
const appFeathers = feathers();
appFeathers.configure(configuration(path.join(__dirname, '..')));
appFeathers.use(compress())
.options('*', cors())
.use(cors())
.use(favicon(path.join(appFeathers.get('public'), 'favicon.ico')))
.use('/', serveStatic(appFeathers.get('public')))
.use(bodyParser.json())
.use(bodyParser.urlencoded({extended: true}))
.configure(hooks())
.configure(rest())
.configure(socketio())
.configure(services)
.configure(middleware)
.configure(authentication());
module.exports = appFeathers;
文件:後端\設置\ default.json
{
"host": "localhost",
"port": 3001,
"mysql_connection": "mysql://CONNECTION_STRING",
"public": "../public/",
"auth": {
"idField": "id",
"token": {
"secret": "SECRET_KEY"
},
"local": {}
}
}
在前端的工作部件:
<template>
<div class="vttIndex">
idnex.vue
todo: eagle.js slideshow
todo: first info
<ul>
<li v-for="message in listMessages">
{{ message }}
</li>
</ul>
</div>
</template>
<script>
import feathers from 'feathers/client';
import socketio from 'feathers-socketio/client';
import hooks from 'feathers-hooks';
import io from 'socket.io-client';
import authentication from 'feathers-authentication/client';
import * as process from "../nuxt.config";
const vttSocket = io(process.env.backendUrl);
const vttFeathers = feathers()
.configure(socketio(vttSocket))
.configure(hooks())
.configure(authentication());
const serviceMessage = vttFeathers.service('messages');
vttFeathers.authenticate({
type: 'token',
'token ': 'SECRET_KEY'
}).then(function(result){
console.log('Authenticated!', result);
}).catch(function(error){
console.error('Error authenticating!', error);
});
export default {
layout: 'default',
data: function() {
return {
listMessages: []
}
},
mounted: function() {
serviceMessage.find().then(page => {
this.listMessages = page.data;
});
serviceMessage.on('created', (serviceMessage) => {
this.listMessages.push(serviceMessage);
});
}
}
</script>
至於原因,我有後臺的JSON文件的密鑰。如您所見,現在我只嘗試記錄控制檯消息。它正在做一些事情,我的錯誤消息是從那裏來的。
問題
我在哪裏丟失有什麼這個功能?
目標
萬一它的需要。我的目標是在我的客戶端使用令牌選擇所有「公共」數據,然後管理部分可能使用0auth。所以一般的'SELECT'東西通過一個令牌來保證,而不是根本不認證。
解決方案
好吧,我解決了這個問題,有點。我首先需要創建一個用戶。然後,我需要與用戶進行本地登錄。這返回一個令牌。如果我使用它,那麼根本沒有問題。
你明白了!登錄用戶是獲得accessToken的預期工作流程。 –