Compare commits

...

10 Commits

Author SHA1 Message Date
Ilia Mashkov
a98a9c2c79 feat(Auth): create useAuthStore hook representing auth store using zustand 2026-03-16 18:31:53 +03:00
Ilia Mashkov
5acb326c03 feat(api): create base api using ky 2026-03-16 18:30:49 +03:00
Ilia Mashkov
3214fe716d feat(Auth): split AuthStore type to State and Actions 2026-03-16 18:29:56 +03:00
Ilia Mashkov
31f9bac50b chore: add testing packages 2026-03-16 18:29:03 +03:00
Ilia Mashkov
6bfcc4db24 chore: add testing packages 2026-03-16 18:28:41 +03:00
Ilia Mashkov
fa3f461add feature(auth): create types 2026-03-16 13:30:09 +03:00
Ilia Mashkov
7ab2d3b812 chore: setup absolute imports 2026-03-16 13:20:53 +03:00
Ilia Mashkov
d28ecef77c feat: fill the expose section of the federation config 2026-03-16 12:56:22 +03:00
Ilia Mashkov
85d296942b chore: install zustand for state management and ky for data fetching 2026-03-16 12:55:35 +03:00
Ilia Mashkov
5267c35d15 feat(User): create User interface 2026-03-16 12:54:52 +03:00
17 changed files with 1520 additions and 12 deletions

View File

@@ -7,26 +7,38 @@
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
"preview": "vite preview",
"test:unit": "vitest",
"test:run": "vitest run",
"test:coverage": "vitest run --coverage"
},
"dependencies": {
"ky": "^1.14.3",
"react": "^19.2.0",
"react-dom": "^19.2.0"
"react-dom": "^19.2.0",
"zustand": "^5.0.12"
},
"devDependencies": {
"@eslint/js": "^9.39.1",
"@module-federation/vite": "^1.12.3",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.2",
"@testing-library/user-event": "^14.6.1",
"@types/node": "^24.10.1",
"@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.4",
"@vitest/coverage-v8": "^4.1.0",
"babel-plugin-react-compiler": "^1.0.0",
"eslint": "^9.39.1",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.24",
"globals": "^16.5.0",
"jsdom": "^29.0.0",
"typescript": "~5.9.3",
"typescript-eslint": "^8.48.0",
"vite": "^7.3.1"
"vite": "^7.3.1",
"vitest": "^4.1.0"
}
}

View File

@@ -0,0 +1 @@
export * from "./model";

View File

@@ -0,0 +1 @@
export * from "./types/types";

View File

@@ -0,0 +1,10 @@
export interface User {
/**
* User's unique identifier.
*/
id: string;
/**
* User's email address.
*/
email: string;
}

View File

@@ -1,2 +1,3 @@
export * from "./lib";
export * from "./ui";
export * from "./model";

View File

@@ -0,0 +1,2 @@
export * from "./types/service";
export * from "./types/store";

View File

@@ -0,0 +1,9 @@
import { create } from "zustand";
import type { AuthStore } from "../../types/store";
export const useAuthStore = create<AuthStore>()((set) => ({
user: undefined,
status: "idle",
setUser: (user) => set({ user }),
setStatus: (status) => set({ status }),
}));

View File

@@ -0,0 +1,18 @@
import type { User } from "entities/User";
export interface AuthResponse {
/**
* Access token for the authenticated user.
*/
accessToken: string;
/**
* User object associated with the access token.
*/
user: User;
}
export type AuthStatus =
| "idle"
| "loading"
| "authenticated"
| "unauthenticated";

View File

@@ -0,0 +1,20 @@
import type { User } from "entities/User";
import type { AuthStatus } from "./service";
export interface AuthStoreState {
/**
* User's credentials
*/
user?: User;
/**
* Authentication status
*/
status: AuthStatus;
}
export interface AuthStoreActions {
setUser: (user: AuthStoreState["user"] | undefined) => void;
setStatus: (status: AuthStoreState["status"]) => void;
}
export type AuthStore = AuthStoreState & AuthStoreActions;

View File

@@ -0,0 +1,2 @@
export const BASE_URL =
import.meta.env.VITE_API_BASE_URL || "https://localhost:3001";

View File

@@ -0,0 +1,6 @@
import ky from "ky";
import { BASE_URL } from "./endpoint";
export const api = ky.create({
prefixUrl: BASE_URL,
});

View File

@@ -0,0 +1,2 @@
export * from "./api/endpoint";
export * from "./api/httpClient";

View File

@@ -0,0 +1 @@
import "@testing-library/jest-dom";

View File

@@ -5,7 +5,7 @@
"useDefineForClassFields": true,
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"types": ["vite/client"],
"types": ["vite/client", "vitest/globals"],
"skipLibCheck": true,
/* Bundler mode */
@@ -22,7 +22,17 @@
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
"noUncheckedSideEffectImports": true,
/* FSD path aliases */
"baseUrl": ".",
"paths": {
"shared/*": ["src/shared/*"],
"entities/*": ["src/entities/*"],
"features/*": ["src/features/*"],
"widgets/*": ["src/widgets/*"],
"app/*": ["src/app/*"]
}
},
"include": ["src"]
}

View File

@@ -1,8 +1,18 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { federation } from "@module-federation/vite";
import path from "path";
export default defineConfig({
resolve: {
alias: {
shared: path.resolve(__dirname, "src/shared"),
entities: path.resolve(__dirname, "src/entities"),
features: path.resolve(__dirname, "src/features"),
widgets: path.resolve(__dirname, "src/widgets"),
app: path.resolve(__dirname, "src/app"),
},
},
plugins: [
react({
babel: {
@@ -13,7 +23,12 @@ export default defineConfig({
name: "auth-react-remote",
manifest: true,
filename: "remoteEntry.js",
exposes: {},
exposes: {
"./AuthGuard": "./src/features/auth",
"./useAuth": "./src/features/auth",
"./RegisterForm": "./src/features/auth",
"./LoginForm": "./src/features/auth",
},
shared: ["react", "react-dom", "zustand"],
}),
],

32
vitest.config.ts Normal file
View File

@@ -0,0 +1,32 @@
import { defineConfig } from "vitest/config";
import react from "@vitejs/plugin-react";
import path from "path";
export default defineConfig({
plugins: [
react({
babel: {
plugins: [["babel-plugin-react-compiler", {}]],
},
}),
],
resolve: {
alias: {
shared: path.resolve(__dirname, "src/shared"),
entities: path.resolve(__dirname, "src/entities"),
features: path.resolve(__dirname, "src/features"),
widgets: path.resolve(__dirname, "src/widgets"),
app: path.resolve(__dirname, "src/app"),
},
},
test: {
globals: true,
environment: "jsdom",
setupFiles: ["./src/shared/config/test/setup.ts"],
coverage: {
provider: "v8",
reporter: ["text", "json", "html"],
exclude: ["node_modules/", "src/test/"],
},
},
});

1378
yarn.lock

File diff suppressed because it is too large Load Diff