nuxt-admin:
container_name: gorodbrand.nuxt_admin
build: ./docker/node-nuxt-public
ports:
- "3101:3000"
volumes:
- ./nuxt_admin:/usr/nuxt-app
nuxt-public:
container_name: gorodbrand.nuxt_public
build: ./docker/node-nuxt-admin
ports:
- "3102:3000"
volumes:
- ./nuxt_admin:/usr/nuxt-app
import {Secure} from "../api/Secure";
import {ACCESS_TOKEN} from "../store/mutation-types";
export default async function ({store, req, redirect}) {
let auth = await checkAccessToken(store.getters[ACCESS_TOKEN])
if (!auth) {
return redirect('/login')
}
};
async function checkAccessToken(token) {
let secure = new Secure()
try {
let response = await secure.checkToken({token})
return response.code === 0;
} catch (e) {
return false
} finally {
secure = undefined
}
}
import axios, {AxiosRequestConfig} from "axios";
export class Api {
_api(method){
return `${process.env.api}/${method}`;
}
/**
*
* @param method
* @param config
* @returns {Promise<AxiosResponse<T>>}
*/
_httpGet(method, config) {
return axios.get(this._api(method), config);
}
/**
*
* @param method
* @param data
* @param config
* @returns {Promise<AxiosResponse<T>>}
*/
_httpPost(method, data, config) {
return axios.post(this._api(method), data, config);
}
}
import {Api} from "./Api";
export class Secure extends Api {
/**
* @returns {Promise<T>}
* @param raw_json
*/
async getAccessToken(raw_json) {
let response = await this._httpPost("secure.getAccessToken", raw_json);
return response.data;
}
/**
*
* @param raw_json
* @returns {Promise<T>}
*/
async checkToken(raw_json) {
let response = await this._httpPost("secure.checkToken", raw_json);
return response.data;
}
}