code: nextjs,frontends,auth (4 files)

This commit is contained in:
2025-12-26 00:36:03 +00:00
parent 83763af54b
commit bf85f6208c
4 changed files with 64 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
/**
* @file package_validation.hpp
* @brief Validation functions for Package entity
*/
#ifndef DBAL_PACKAGE_VALIDATION_HPP
#define DBAL_PACKAGE_VALIDATION_HPP
#include <string>
#include <regex>
namespace dbal {
namespace validation {
/**
* Validate package name (1-255 characters)
*/
inline bool isValidPackageName(const std::string& name) {
return !name.empty() && name.length() <= 255;
}
/**
* Validate semver version format (X.Y.Z)
*/
inline bool isValidSemver(const std::string& version) {
static const std::regex semver_pattern(R"(^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$)");
return std::regex_match(version, semver_pattern);
}
/**
* Generate package key from name and version
*/
inline std::string packageKey(const std::string& name, const std::string& version) {
return name + "@" + version;
}
} // namespace validation
} // namespace dbal
#endif

View File

@@ -5,7 +5,7 @@ import { Box } from '@mui/material'
import type { BoxProps } from '@mui/material'
import { TabsContext } from './tabs-context'
export interface TabsListProps extends BoxProps {}
export type TabsListProps = BoxProps
const TabsList = forwardRef<HTMLDivElement, TabsListProps>(
({ children, sx, ...props }, ref) => {

View File

@@ -2,6 +2,7 @@ import type { User } from '@/lib/level-types'
import { fetchSession } from '@/lib/auth/api/fetch-session'
import { login as loginRequest } from '@/lib/auth/api/login'
import { logout as logoutRequest } from '@/lib/auth/api/logout'
import { register as registerRequest } from '@/lib/auth/api/register'
import type { AuthState, AuthUser } from './auth-types'
const roleLevels: Record<string, number> = {
@@ -64,6 +65,28 @@ export class AuthStore {
}
}
async register(username: string, email: string, password: string): Promise<void> {
this.setState({
...this.state,
isLoading: true,
})
try {
const user = await registerRequest(username, email, password)
this.setState({
user: this.mapUserToAuthUser(user),
isAuthenticated: true,
isLoading: false,
})
} catch (error) {
this.setState({
...this.state,
isLoading: false,
})
throw error
}
}
async logout(): Promise<void> {
this.setState({
...this.state,

View File

@@ -21,6 +21,7 @@ export interface AuthState {
export interface UseAuthReturn extends AuthState {
login: (identifier: string, password: string) => Promise<void>
register: (username: string, email: string, password: string) => Promise<void>
logout: () => Promise<void>
refresh: () => Promise<void>
}