|
|
@@ -1,13 +1,15 @@
|
|
|
-import { mapMutations } from 'vuex'
|
|
|
|
|
|
-export default function ({route, store, req, res, redirect}) {
|
|
|
+export default function (context) {
|
|
|
+ const {app, route, store, req, res, redirect, next} = context;
|
|
|
let isClient = process.client;
|
|
|
let isServer = process.server;
|
|
|
- let redirectURL = '/login';
|
|
|
let token, path;
|
|
|
|
|
|
token = store.state.token;
|
|
|
|
|
|
+ console.log('token', token);
|
|
|
+
|
|
|
+ // console.log("cookies", cook);
|
|
|
//在服务端
|
|
|
if (isServer) {
|
|
|
path = req.originalUrl;
|
|
|
@@ -19,27 +21,45 @@ export default function ({route, store, req, res, redirect}) {
|
|
|
|
|
|
console.log("path:"+path);
|
|
|
let mainPath = path.split("?")[0];
|
|
|
- store.commit('saveOriginPath', path);
|
|
|
-
|
|
|
- if (!token && mainPath !== "/" && mainPath !=="/login" && mainPath !== "/register" && mainPath !=="/error" && mainPath !== "/api/receiveIDToken") {
|
|
|
- let return_uri = encodeURIComponent("http://localhost:3000/receiveIDToken");
|
|
|
- store.commit('saveOriginPath', path);
|
|
|
- console.log("encoded path");
|
|
|
- let url = 'http://localhost:3000/api/interaction?'+
|
|
|
- 'client_id='+ 'seec-portal' +
|
|
|
- '&scope=openid' +
|
|
|
- '&redirect_uri=' + return_uri +
|
|
|
- '&response_type=code';
|
|
|
-
|
|
|
- // req.headers.cookies.set(
|
|
|
- // 'interaction',
|
|
|
- // 'seec-114514-1919810', //可替换为token
|
|
|
- // {
|
|
|
- // maxAge: 10 * 60 * 1000, // cookie有效时长
|
|
|
- // sameSite: none
|
|
|
- // }
|
|
|
- // );
|
|
|
-
|
|
|
- redirect(url);
|
|
|
+ console.log('mainPath', mainPath);
|
|
|
+
|
|
|
+ if(mainPath === "/setToken"){
|
|
|
+ try{
|
|
|
+ const params = path.split("?")[1].split('&');
|
|
|
+ let obj = {};
|
|
|
+ if(params.length !== 5
|
|
|
+ || params[0].split("=")[0] !== "origin_path"
|
|
|
+ || params[1].split("=")[0] !== "token"
|
|
|
+ || params[2].split("=")[0] !== "id"
|
|
|
+ || params[3].split("=")[0] !== "name"
|
|
|
+ || params[4].split("=")[0] !== "phone"
|
|
|
+ ){
|
|
|
+ redirect('/error');
|
|
|
+ }else{
|
|
|
+ for(let i = 0; i < 5 ; i++){
|
|
|
+ obj[params[i].split("=")[0]] = params[i].split("=")[1];
|
|
|
+
|
|
|
+ }
|
|
|
+ console.log('obj', obj);
|
|
|
+ let new_token = obj['token'];
|
|
|
+ let origin_path = obj['origin_path'];
|
|
|
+ let user = {id: obj['id'], name: obj['name'], phone: obj['phone']};
|
|
|
+
|
|
|
+ app.$cookies.set('token', new_token);
|
|
|
+ app.$cookies.set('user', user);
|
|
|
+
|
|
|
+ redirect(origin_path);
|
|
|
+ }
|
|
|
+
|
|
|
+ }catch (e) {
|
|
|
+ console.log("e: ", e);
|
|
|
+ redirect('/error');
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ else if (!token && mainPath !== "/" && mainPath !=="/login" && mainPath !== "/register" && mainPath !=="/error" && mainPath !== "/api/receiveIDToken") {
|
|
|
+ redirect('/api/authenticate?path=' + mainPath);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|