Multi-environment and multi-user construction
This commit is contained in:
@@ -2,12 +2,17 @@ import { defineStore } from 'pinia';
|
||||
import { computed, ref } from 'vue';
|
||||
import type {
|
||||
AuthUserDto,
|
||||
CreateOrganizationRequest,
|
||||
LoginChallengeResponse,
|
||||
LoginOrganizationChoiceResponse,
|
||||
LoginResponse,
|
||||
LoginResult,
|
||||
OrganizationMembershipDto,
|
||||
RegisterChallengeResponse,
|
||||
RegisterOrganizationRequest,
|
||||
UpdateProfileRequest,
|
||||
} from '@mento/shared';
|
||||
import { isLoginOrganizationChoice } from '@mento/shared';
|
||||
import { api } from '@/lib/api';
|
||||
|
||||
const TOKEN_KEY = 'mento_token';
|
||||
@@ -79,11 +84,11 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
}
|
||||
|
||||
async function login(identifier: string, password: string) {
|
||||
const { data } = await api.post<LoginResponse>('/auth/login', {
|
||||
const { data } = await api.post<LoginResult>('/auth/login', {
|
||||
identifier,
|
||||
password,
|
||||
});
|
||||
persist(data);
|
||||
return applyLoginResult(data);
|
||||
}
|
||||
|
||||
async function requestLoginOtp(mobile: string) {
|
||||
@@ -94,10 +99,40 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
}
|
||||
|
||||
async function verifyLoginOtp(challengeId: string, code: string) {
|
||||
const { data } = await api.post<LoginResponse>('/auth/login/otp/verify', {
|
||||
const { data } = await api.post<LoginResult>('/auth/login/otp/verify', {
|
||||
challengeId,
|
||||
code,
|
||||
});
|
||||
return applyLoginResult(data);
|
||||
}
|
||||
|
||||
function applyLoginResult(data: LoginResult): LoginOrganizationChoiceResponse | void {
|
||||
if (isLoginOrganizationChoice(data)) return data;
|
||||
persist(data);
|
||||
}
|
||||
|
||||
async function selectOrganization(selectionToken: string, organizationId: string) {
|
||||
const { data } = await api.post<LoginResponse>('/auth/select-organization', {
|
||||
selectionToken,
|
||||
organizationId,
|
||||
});
|
||||
persist(data);
|
||||
}
|
||||
|
||||
async function switchOrganization(organizationId: string) {
|
||||
const { data } = await api.post<LoginResponse>('/auth/switch-organization', {
|
||||
organizationId,
|
||||
});
|
||||
persist(data);
|
||||
}
|
||||
|
||||
async function listOrganizations() {
|
||||
const { data } = await api.get<OrganizationMembershipDto[]>('/auth/organizations');
|
||||
return data;
|
||||
}
|
||||
|
||||
async function createOrganization(payload: CreateOrganizationRequest) {
|
||||
const { data } = await api.post<LoginResponse>('/organizations', payload);
|
||||
persist(data);
|
||||
}
|
||||
|
||||
@@ -174,6 +209,10 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
login,
|
||||
requestLoginOtp,
|
||||
verifyLoginOtp,
|
||||
selectOrganization,
|
||||
switchOrganization,
|
||||
listOrganizations,
|
||||
createOrganization,
|
||||
startRegister,
|
||||
verifyRegister,
|
||||
logout,
|
||||
|
||||
Reference in New Issue
Block a user