|
|
@@ -2,6 +2,19 @@ import { api } from "src/boot/axios";
|
|
|
import { Cookies } from "quasar";
|
|
|
import { permissionStore } from "src/stores/permission";
|
|
|
import { userStore } from "src/stores/user";
|
|
|
+import { clearAuthSession, isOwnerUser } from "src/helpers/authAccess";
|
|
|
+
|
|
|
+const assertOwnerAccess = (user) => {
|
|
|
+ if (isOwnerUser(user)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ clearAuthSession();
|
|
|
+
|
|
|
+ const error = new Error("Acesso permitido apenas para proprietários.");
|
|
|
+ error.response = { data: { message: error.message } };
|
|
|
+ throw error;
|
|
|
+};
|
|
|
|
|
|
export const useAuth = () => {
|
|
|
const login = async (email, password) => {
|
|
|
@@ -13,6 +26,7 @@ export const useAuth = () => {
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
const payload = response.data.payload;
|
|
|
+ assertOwnerAccess(payload.user);
|
|
|
|
|
|
const accessTokenExpiresIn = new Date(
|
|
|
new Date().getTime() + payload.expires_in * 1000,
|
|
|
@@ -68,6 +82,7 @@ export const useAuth = () => {
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
const payload = response.data.payload;
|
|
|
+ assertOwnerAccess(payload.user);
|
|
|
|
|
|
const accessTokenExpiresIn = new Date(
|
|
|
new Date().getTime() + payload.expires_in * 1000,
|