This commit is contained in:
2024-02-28 23:43:36 +03:00
parent db6c735fdc
commit 5134d44e39
19 changed files with 2328 additions and 1793 deletions

48
src/__data__/api/api.ts Normal file
View File

@@ -0,0 +1,48 @@
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
import { getConfigValue } from "@ijl/cli";
import { keycloak } from "../kc";
export const api = createApi({
reducerPath: "auth",
baseQuery: fetchBaseQuery({
baseUrl: getConfigValue("journal.back.url"),
headers: {
Authorization: `Bearer ${keycloak.token}`,
"Content-Type": "application/json;charset=utf-8",
},
}),
endpoints: (builder) => ({
lessonList: builder.query({
query: () => '/lesson/list'
})
// signIn: builder.mutation<SignInResponce, SignInRequestBody>({
// query: ({ login, password }) => ({
// url: URLs.queryApi.login,
// method: 'POST',
// body: { login, password },
// }),
// }),
// recoverPassword: builder.mutation<{ error?: string }, { email: string }>({
// query: ({ email }) => ({
// url: URLs.queryApi.revoverPassword,
// method: 'POST',
// body: { email }
// })
// }),
// recoverPasswordConfirm: builder.mutation<{ error?: string }, { code: string }>({
// query: ({ code }) => ({
// url: URLs.queryApi.revoverPasswordConfirm,
// method: 'POST',
// body: { code }
// })
// }),
// recoverPasswordNewPassword: builder.mutation<{ error?: string }, { newPassword: string }>({
// query: ({ newPassword }) => ({
// url: URLs.queryApi.revoverPasswordNew,
// method: 'POST',
// body: { newPassword }
// })
// })
}),
});

View File

@@ -3,7 +3,7 @@ import Keycloak from 'keycloak-js';
export const keycloak = new Keycloak({
url: 'https://kc.inno-js.ru',
realm: 'inno-js',
clientId: 'jurnal'
clientId: 'journal'
});
window.keycloak = keycloak;

49
src/__data__/model.ts Normal file
View File

@@ -0,0 +1,49 @@
interface TokenData {
exp: number;
iat: number;
auth_time: number;
jti: string;
iss: string;
aud: string[];
sub: string;
typ: string;
azp: string;
nonce: string;
session_state: string;
acr: string;
'allowed-origins': string[];
realm_access: Realmaccess;
resource_access: Resourceaccess;
scope: string;
sid: string;
email_verified: boolean;
name: string;
preferred_username: string;
given_name: string;
family_name: string;
email: string;
}
interface Resourceaccess {
'realm-management': Realmaccess;
jurnal: Realmaccess;
broker: Realmaccess;
account: Realmaccess;
'microfrontend-admin': Realmaccess
}
interface Realmaccess {
roles: string[];
}
export interface UserData extends TokenData {
sub: string;
gravatar: string;
email_verified: boolean;
attributes: Record<string, string[]>
name: string;
preferred_username: string;
given_name: string;
family_name: string;
email: string;
}

View File

@@ -0,0 +1,10 @@
import { createSlice } from '@reduxjs/toolkit';
import { UserData } from '../model';
export const userSlice = createSlice({
name: 'user',
initialState: null as UserData,
reducers: {
}
})

16
src/__data__/store.ts Normal file
View File

@@ -0,0 +1,16 @@
import { configureStore } from '@reduxjs/toolkit';
import { api } from './api/api';
import { userSlice } from './slices/user';
export const createStore= (preloadedState = {}) => configureStore({
preloadedState,
reducer: {
[api.reducerPath]: api.reducer,
[userSlice.name]: userSlice.reducer
},
middleware: getDefaultMiddleware =>
getDefaultMiddleware().concat(api.middleware),
});
export type Store = ReturnType<ReturnType<typeof createStore>['getState']>;