list users
This commit is contained in:
@@ -228,3 +228,19 @@ pub enum CreateUserError {
|
|||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Unknown(#[from] anyhow::Error),
|
Unknown(#[from] anyhow::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An admin request to list all users
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
pub struct ListUsersRequest {}
|
||||||
|
|
||||||
|
impl ListUsersRequest {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum ListUsersError {
|
||||||
|
#[error(transparent)]
|
||||||
|
Unknown(#[from] anyhow::Error),
|
||||||
|
}
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ pub trait AuthMetrics: Clone + Send + Sync + 'static {
|
|||||||
fn record_user_creation_success(&self) -> impl Future<Output = ()> + Send;
|
fn record_user_creation_success(&self) -> impl Future<Output = ()> + Send;
|
||||||
fn record_user_creation_failure(&self) -> impl Future<Output = ()> + Send;
|
fn record_user_creation_failure(&self) -> impl Future<Output = ()> + Send;
|
||||||
|
|
||||||
|
fn record_user_list_success(&self) -> impl Future<Output = ()> + Send;
|
||||||
|
fn record_user_list_failure(&self) -> impl Future<Output = ()> + Send;
|
||||||
|
|
||||||
fn record_auth_session_creation_success(&self) -> impl Future<Output = ()> + Send;
|
fn record_auth_session_creation_success(&self) -> impl Future<Output = ()> + Send;
|
||||||
fn record_auth_session_creation_failure(&self) -> impl Future<Output = ()> + Send;
|
fn record_auth_session_creation_failure(&self) -> impl Future<Output = ()> + Send;
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ use super::models::{
|
|||||||
FilePath, ListFilesError, ListFilesRequest, RenameEntryError, RenameEntryRequest,
|
FilePath, ListFilesError, ListFilesRequest, RenameEntryError, RenameEntryRequest,
|
||||||
},
|
},
|
||||||
user::{
|
user::{
|
||||||
CreateUserError, CreateUserRequest, LoginUserError, LoginUserRequest, LoginUserResponse,
|
CreateUserError, CreateUserRequest, ListUsersError, ListUsersRequest, LoginUserError,
|
||||||
RegisterUserError, RegisterUserRequest, User,
|
LoginUserRequest, LoginUserResponse, RegisterUserError, RegisterUserRequest, User,
|
||||||
},
|
},
|
||||||
user_warren::{
|
user_warren::{
|
||||||
UserWarren,
|
UserWarren,
|
||||||
@@ -125,6 +125,10 @@ pub trait AuthService: Clone + Send + Sync + 'static {
|
|||||||
&self,
|
&self,
|
||||||
request: AuthRequest<CreateUserRequest>,
|
request: AuthRequest<CreateUserRequest>,
|
||||||
) -> impl Future<Output = Result<User, AuthError<CreateUserError>>> + Send;
|
) -> impl Future<Output = Result<User, AuthError<CreateUserError>>> + Send;
|
||||||
|
fn list_users(
|
||||||
|
&self,
|
||||||
|
request: AuthRequest<ListUsersRequest>,
|
||||||
|
) -> impl Future<Output = Result<Vec<User>, AuthError<ListUsersError>>> + Send;
|
||||||
|
|
||||||
fn create_auth_session(
|
fn create_auth_session(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -74,6 +74,11 @@ pub trait AuthNotifier: Clone + Send + Sync + 'static {
|
|||||||
fn user_registered(&self, user: &User) -> impl Future<Output = ()> + Send;
|
fn user_registered(&self, user: &User) -> impl Future<Output = ()> + Send;
|
||||||
fn user_logged_in(&self, response: &LoginUserResponse) -> impl Future<Output = ()> + Send;
|
fn user_logged_in(&self, response: &LoginUserResponse) -> impl Future<Output = ()> + Send;
|
||||||
fn user_created(&self, creator: &User, created: &User) -> impl Future<Output = ()> + Send;
|
fn user_created(&self, creator: &User, created: &User) -> impl Future<Output = ()> + Send;
|
||||||
|
/// Lists all the users (admin action)
|
||||||
|
///
|
||||||
|
/// * `user`: The user who requested the list
|
||||||
|
/// * `users`: The users from the list
|
||||||
|
fn users_listed(&self, user: &User, users: &Vec<User>) -> impl Future<Output = ()> + Send;
|
||||||
|
|
||||||
fn auth_session_created(&self, user_id: &Uuid) -> impl Future<Output = ()> + Send;
|
fn auth_session_created(&self, user_id: &Uuid) -> impl Future<Output = ()> + Send;
|
||||||
fn auth_session_fetched(
|
fn auth_session_fetched(
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ use crate::domain::warren::models::{
|
|||||||
FilePath, ListFilesError, ListFilesRequest, RenameEntryError, RenameEntryRequest,
|
FilePath, ListFilesError, ListFilesRequest, RenameEntryError, RenameEntryRequest,
|
||||||
},
|
},
|
||||||
user::{
|
user::{
|
||||||
CreateUserError, CreateUserRequest, User, VerifyUserPasswordError,
|
CreateUserError, CreateUserRequest, ListUsersError, ListUsersRequest, User,
|
||||||
VerifyUserPasswordRequest,
|
VerifyUserPasswordError, VerifyUserPasswordRequest,
|
||||||
},
|
},
|
||||||
user_warren::{
|
user_warren::{
|
||||||
UserWarren,
|
UserWarren,
|
||||||
@@ -74,10 +74,16 @@ pub trait AuthRepository: Clone + Send + Sync + 'static {
|
|||||||
&self,
|
&self,
|
||||||
request: CreateUserRequest,
|
request: CreateUserRequest,
|
||||||
) -> impl Future<Output = Result<User, CreateUserError>> + Send;
|
) -> impl Future<Output = Result<User, CreateUserError>> + Send;
|
||||||
|
fn list_users(
|
||||||
|
&self,
|
||||||
|
request: ListUsersRequest,
|
||||||
|
) -> impl Future<Output = Result<Vec<User>, ListUsersError>> + Send;
|
||||||
|
|
||||||
fn verify_user_password(
|
fn verify_user_password(
|
||||||
&self,
|
&self,
|
||||||
request: VerifyUserPasswordRequest,
|
request: VerifyUserPasswordRequest,
|
||||||
) -> impl Future<Output = Result<User, VerifyUserPasswordError>> + Send;
|
) -> impl Future<Output = Result<User, VerifyUserPasswordError>> + Send;
|
||||||
|
|
||||||
fn create_auth_session(
|
fn create_auth_session(
|
||||||
&self,
|
&self,
|
||||||
request: CreateAuthSessionRequest,
|
request: CreateAuthSessionRequest,
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ use crate::{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
user::{
|
user::{
|
||||||
CreateUserError, CreateUserRequest, LoginUserError, LoginUserRequest,
|
CreateUserError, CreateUserRequest, ListUsersError, ListUsersRequest,
|
||||||
LoginUserResponse, RegisterUserError, RegisterUserRequest, User,
|
LoginUserError, LoginUserRequest, LoginUserResponse, RegisterUserError,
|
||||||
|
RegisterUserRequest, User,
|
||||||
},
|
},
|
||||||
user_warren::{
|
user_warren::{
|
||||||
UserWarren,
|
UserWarren,
|
||||||
@@ -165,6 +166,32 @@ where
|
|||||||
result.map_err(AuthError::Custom)
|
result.map_err(AuthError::Custom)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn list_users(
|
||||||
|
&self,
|
||||||
|
request: AuthRequest<ListUsersRequest>,
|
||||||
|
) -> Result<Vec<User>, AuthError<ListUsersError>> {
|
||||||
|
let (session, request) = request.unpack();
|
||||||
|
|
||||||
|
let response = self
|
||||||
|
.fetch_auth_session(FetchAuthSessionRequest::new(session.session_id().clone()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if !response.user().admin() {
|
||||||
|
return Err(AuthError::InsufficientPermissions);
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = self.repository.list_users(request).await;
|
||||||
|
|
||||||
|
if let Ok(users) = result.as_ref() {
|
||||||
|
self.metrics.record_user_list_success().await;
|
||||||
|
self.notifier.users_listed(response.user(), users).await;
|
||||||
|
} else {
|
||||||
|
self.metrics.record_user_list_failure().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.map_err(AuthError::Custom)
|
||||||
|
}
|
||||||
|
|
||||||
async fn create_auth_session(
|
async fn create_auth_session(
|
||||||
&self,
|
&self,
|
||||||
request: CreateAuthSessionRequest,
|
request: CreateAuthSessionRequest,
|
||||||
|
|||||||
32
backend/src/lib/inbound/http/handlers/admin/list_users.rs
Normal file
32
backend/src/lib/inbound/http/handlers/admin/list_users.rs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
use axum::{extract::State, http::StatusCode};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
domain::warren::{
|
||||||
|
models::{
|
||||||
|
auth_session::AuthRequest,
|
||||||
|
user::{ListUsersRequest, User},
|
||||||
|
},
|
||||||
|
ports::{AuthService, WarrenService},
|
||||||
|
},
|
||||||
|
inbound::http::{
|
||||||
|
AppState,
|
||||||
|
handlers::{UserData, extractors::SessionIdHeader},
|
||||||
|
responses::{ApiError, ApiSuccess},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub async fn list_users<WS: WarrenService, AS: AuthService>(
|
||||||
|
State(state): State<AppState<WS, AS>>,
|
||||||
|
SessionIdHeader(session): SessionIdHeader,
|
||||||
|
) -> Result<ApiSuccess<Vec<UserData>>, ApiError> {
|
||||||
|
state
|
||||||
|
.auth_service
|
||||||
|
.list_users(AuthRequest::new(session, ListUsersRequest::new()))
|
||||||
|
.await
|
||||||
|
.map(|users| ApiSuccess::new(StatusCode::OK, get_user_data(users)))
|
||||||
|
.map_err(ApiError::from)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_user_data(users: Vec<User>) -> Vec<UserData> {
|
||||||
|
users.into_iter().map(Into::into).collect()
|
||||||
|
}
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
mod create_user;
|
mod create_user;
|
||||||
use create_user::create_user;
|
mod list_users;
|
||||||
|
|
||||||
use axum::{Router, routing::post};
|
use create_user::create_user;
|
||||||
|
use list_users::list_users;
|
||||||
|
|
||||||
|
use axum::{
|
||||||
|
Router,
|
||||||
|
routing::{get, post},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
domain::warren::ports::{AuthService, WarrenService},
|
domain::warren::ports::{AuthService, WarrenService},
|
||||||
@@ -9,5 +15,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn routes<WS: WarrenService, AS: AuthService>() -> Router<AppState<WS, AS>> {
|
pub fn routes<WS: WarrenService, AS: AuthService>() -> Router<AppState<WS, AS>> {
|
||||||
Router::new().route("/users", post(create_user))
|
Router::new()
|
||||||
|
.route("/users", get(list_users))
|
||||||
|
.route("/users", post(create_user))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ pub mod warrens;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, PartialEq)]
|
#[derive(Debug, Clone, Serialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
/// A session user that can be safely sent to the client
|
/// A user that can be safely sent to the client
|
||||||
pub(super) struct UserData {
|
pub(super) struct UserData {
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
name: String,
|
name: String,
|
||||||
|
|||||||
@@ -145,6 +145,13 @@ impl AuthMetrics for MetricsDebugLogger {
|
|||||||
tracing::debug!("[Metrics] User creation failed");
|
tracing::debug!("[Metrics] User creation failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn record_user_list_success(&self) -> () {
|
||||||
|
tracing::debug!("[Metrics] User list succeeded");
|
||||||
|
}
|
||||||
|
async fn record_user_list_failure(&self) -> () {
|
||||||
|
tracing::debug!("[Metrics] User list failed");
|
||||||
|
}
|
||||||
|
|
||||||
async fn record_auth_session_creation_success(&self) {
|
async fn record_auth_session_creation_success(&self) {
|
||||||
tracing::debug!("[Metrics] Auth session creation succeeded");
|
tracing::debug!("[Metrics] Auth session creation succeeded");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,14 @@ impl AuthNotifier for NotifierDebugLogger {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn users_listed(&self, user: &User, users: &Vec<User>) {
|
||||||
|
tracing::debug!(
|
||||||
|
"[Notifier] Admin user {} listed {} user(s)",
|
||||||
|
user.name(),
|
||||||
|
users.len()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async fn user_logged_in(&self, response: &LoginUserResponse) {
|
async fn user_logged_in(&self, response: &LoginUserResponse) {
|
||||||
tracing::debug!("[Notifier] Logged in user {}", response.user().name());
|
tracing::debug!("[Notifier] Logged in user {}", response.user().name());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ use crate::domain::warren::{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
user::{
|
user::{
|
||||||
CreateUserError, CreateUserRequest, User, UserEmail, UserName, UserPassword,
|
CreateUserError, CreateUserRequest, ListUsersError, ListUsersRequest, User, UserEmail,
|
||||||
VerifyUserPasswordError, VerifyUserPasswordRequest,
|
UserName, UserPassword, VerifyUserPasswordError, VerifyUserPasswordRequest,
|
||||||
},
|
},
|
||||||
user_warren::{
|
user_warren::{
|
||||||
UserWarren,
|
UserWarren,
|
||||||
@@ -348,6 +348,21 @@ impl Postgres {
|
|||||||
|
|
||||||
Ok(ids)
|
Ok(ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn fetch_users(&self, connection: &mut PgConnection) -> Result<Vec<User>, sqlx::Error> {
|
||||||
|
let users: Vec<User> = sqlx::query_as(
|
||||||
|
"
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
users
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.fetch_all(connection)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(users)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WarrenRepository for Postgres {
|
impl WarrenRepository for Postgres {
|
||||||
@@ -519,6 +534,21 @@ impl AuthRepository for Postgres {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn list_users(&self, _request: ListUsersRequest) -> Result<Vec<User>, ListUsersError> {
|
||||||
|
let mut connection = self
|
||||||
|
.pool
|
||||||
|
.acquire()
|
||||||
|
.await
|
||||||
|
.context("Failed to get a PostgreSQL connection")?;
|
||||||
|
|
||||||
|
let users = self
|
||||||
|
.fetch_users(&mut connection)
|
||||||
|
.await
|
||||||
|
.map_err(|e| anyhow!(e))?;
|
||||||
|
|
||||||
|
Ok(users)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_not_found_error(err: &sqlx::Error) -> bool {
|
fn is_not_found_error(err: &sqlx::Error) -> bool {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
BreadcrumbPage,
|
BreadcrumbPage,
|
||||||
BreadcrumbSeparator,
|
BreadcrumbSeparator,
|
||||||
} from '@/components/ui/breadcrumb';
|
} from '@/components/ui/breadcrumb';
|
||||||
import type { BreadcrumbData } from '~/types';
|
import type { BreadcrumbData } from '#shared/types';
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const store = useWarrenStore();
|
const store = useWarrenStore();
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
ContextMenuSeparator,
|
ContextMenuSeparator,
|
||||||
} from '@/components/ui/context-menu';
|
} from '@/components/ui/context-menu';
|
||||||
import { deleteWarrenDirectory, deleteWarrenFile } from '~/lib/api/warrens';
|
import { deleteWarrenDirectory, deleteWarrenFile } from '~/lib/api/warrens';
|
||||||
import type { DirectoryEntry } from '~/types';
|
import type { DirectoryEntry } from '#shared/types';
|
||||||
|
|
||||||
const warrenStore = useWarrenStore();
|
const warrenStore = useWarrenStore();
|
||||||
const renameDialog = useRenameDirectoryDialog();
|
const renameDialog = useRenameDirectoryDialog();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
import type { DirectoryEntry } from '~/types';
|
import type { DirectoryEntry } from '#shared/types';
|
||||||
const { entries } = defineProps<{
|
const { entries } = defineProps<{
|
||||||
entries: DirectoryEntry[];
|
entries: DirectoryEntry[];
|
||||||
}>();
|
}>();
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
} from '@/components/ui/dropdown-menu';
|
} from '@/components/ui/dropdown-menu';
|
||||||
import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar';
|
import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar';
|
||||||
import { logout } from '~/lib/api/auth/logout';
|
import { logout } from '~/lib/api/auth/logout';
|
||||||
import type { AuthUser } from '~/types/auth';
|
import type { AuthUser } from '#shared/types/auth';
|
||||||
|
|
||||||
const { isMobile } = useSidebar();
|
const { isMobile } = useSidebar();
|
||||||
const { user } = defineProps<{
|
const { user } = defineProps<{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import byteSize from 'byte-size';
|
import byteSize from 'byte-size';
|
||||||
import type { UploadFile } from '~/types';
|
import type { UploadFile } from '#shared/types';
|
||||||
|
|
||||||
const emit = defineEmits(['removeFile']);
|
const emit = defineEmits(['removeFile']);
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
AlertDialogTitle,
|
AlertDialogTitle,
|
||||||
AlertDialogTrigger,
|
AlertDialogTrigger,
|
||||||
} from '@/components/ui/alert-dialog';
|
} from '@/components/ui/alert-dialog';
|
||||||
import type { AuthUser } from '~/types/auth';
|
import type { AuthUser } from '#shared/types/auth';
|
||||||
|
|
||||||
const adminStore = useAdminStore();
|
const adminStore = useAdminStore();
|
||||||
// We'll only update this value if there is a user to prevent layout shifts on close
|
// We'll only update this value if there is a user to prevent layout shifts on close
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { AuthUser } from '~/types/auth';
|
import type { AuthUser } from '#shared/types/auth';
|
||||||
|
|
||||||
const { user } = defineProps<{
|
const { user } = defineProps<{
|
||||||
user: AuthUser;
|
user: AuthUser;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { AuthSession } from '~/types/auth';
|
import type { AuthSession } from '#shared/types/auth';
|
||||||
|
|
||||||
const SAME_SITE_SETTINGS = ['strict', 'lax', 'none'] as const;
|
const SAME_SITE_SETTINGS = ['strict', 'lax', 'none'] as const;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,16 @@
|
|||||||
<script setup lang="ts"></script>
|
<script setup lang="ts">
|
||||||
|
import { listUsers } from '~/lib/api/admin/listUsers';
|
||||||
|
|
||||||
|
const adminStore = useAdminStore();
|
||||||
|
|
||||||
|
await useAsyncData('users', async () => {
|
||||||
|
const response = await listUsers();
|
||||||
|
|
||||||
|
if (response.success) {
|
||||||
|
adminStore.users = response.users;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<NuxtLayout name="default">
|
<NuxtLayout name="default">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { toast } from 'vue-sonner';
|
import { toast } from 'vue-sonner';
|
||||||
import type { ApiResponse } from '~/types/api';
|
import type { ApiResponse } from '#shared/types/api';
|
||||||
import type { AuthUser, AuthUserFields } from '~/types/auth';
|
import type { AuthUser, AuthUserFields } from '#shared/types/auth';
|
||||||
import { getApiHeaders } from '..';
|
import { getApiHeaders } from '..';
|
||||||
|
|
||||||
/** Admin function to create a new user */
|
/** Admin function to create a new user */
|
||||||
@@ -32,6 +32,8 @@ export async function createUser(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await refreshNuxtData('users');
|
||||||
|
|
||||||
toast.success('Create user', {
|
toast.success('Create user', {
|
||||||
description: 'Successfully created user',
|
description: 'Successfully created user',
|
||||||
});
|
});
|
||||||
|
|||||||
27
frontend/lib/api/admin/listUsers.ts
Normal file
27
frontend/lib/api/admin/listUsers.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import type { ApiResponse } from '~/shared/types/api';
|
||||||
|
import type { AuthUser } from '~/shared/types/auth';
|
||||||
|
import { getApiHeaders } from '..';
|
||||||
|
|
||||||
|
export async function listUsers(): Promise<
|
||||||
|
{ success: true; users: AuthUser[] } | { success: false }
|
||||||
|
> {
|
||||||
|
const { data } = await useFetch<ApiResponse<AuthUser[]>>(
|
||||||
|
getApiUrl('admin/users'),
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
headers: getApiHeaders(),
|
||||||
|
responseType: 'json',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (data.value == null) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
users: data.value.data,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { AuthSessionType, AuthUser } from '~/types/auth';
|
import type { AuthSessionType, AuthUser } from '#shared/types/auth';
|
||||||
import type { ApiResponse } from '~/types/api';
|
import type { ApiResponse } from '#shared/types/api';
|
||||||
|
|
||||||
export async function getAuthSessionData(params: {
|
export async function getAuthSessionData(params: {
|
||||||
sessionType: AuthSessionType;
|
sessionType: AuthSessionType;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { toast } from 'vue-sonner';
|
import { toast } from 'vue-sonner';
|
||||||
import type { ApiResponse } from '~/types/api';
|
import type { ApiResponse } from '#shared/types/api';
|
||||||
import type { AuthUser } from '~/types/auth';
|
import type { AuthUser } from '#shared/types/auth';
|
||||||
import { getApiHeaders } from '..';
|
import { getApiHeaders } from '..';
|
||||||
|
|
||||||
export async function loginUser(
|
export async function loginUser(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { toast } from 'vue-sonner';
|
import { toast } from 'vue-sonner';
|
||||||
import type { ApiResponse } from '~/types/api';
|
import type { ApiResponse } from '#shared/types/api';
|
||||||
|
|
||||||
export async function registerUser(
|
export async function registerUser(
|
||||||
username: string,
|
username: string,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { toast } from 'vue-sonner';
|
import { toast } from 'vue-sonner';
|
||||||
import type { DirectoryEntry } from '~/types';
|
import type { DirectoryEntry } from '#shared/types';
|
||||||
import type { ApiResponse } from '~/types/api';
|
import type { ApiResponse } from '#shared/types/api';
|
||||||
import type { Warren } from '~/types/warrens';
|
import type { Warren } from '#shared/types/warrens';
|
||||||
import { getApiHeaders } from '.';
|
import { getApiHeaders } from '.';
|
||||||
|
|
||||||
export async function getWarrens(): Promise<Record<string, Warren>> {
|
export async function getWarrens(): Promise<Record<string, Warren>> {
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { AuthUser } from '~/types/auth';
|
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
layout: 'admin',
|
layout: 'admin',
|
||||||
middleware: ['is-admin'],
|
middleware: ['is-admin'],
|
||||||
@@ -8,21 +6,6 @@ definePageMeta({
|
|||||||
|
|
||||||
const session = useAuthSession();
|
const session = useAuthSession();
|
||||||
const adminStore = useAdminStore();
|
const adminStore = useAdminStore();
|
||||||
|
|
||||||
const users: AuthUser[] = [
|
|
||||||
{
|
|
||||||
id: '5a307466-bf2e-4cf2-9b11-61f024e8fa71',
|
|
||||||
name: '409',
|
|
||||||
email: '409dev@protonmail.com',
|
|
||||||
admin: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '99132ce4-045c-4d4b-b957-61f5e99e708b',
|
|
||||||
name: 'test-user',
|
|
||||||
email: 'test@user.com',
|
|
||||||
admin: false,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -41,7 +24,7 @@ const users: AuthUser[] = [
|
|||||||
<ScrollArea class="max-h-96">
|
<ScrollArea class="max-h-96">
|
||||||
<div class="flex flex-col gap-4">
|
<div class="flex flex-col gap-4">
|
||||||
<AdminUserListing
|
<AdminUserListing
|
||||||
v-for="user in users"
|
v-for="user in adminStore.users"
|
||||||
:key="user.id"
|
:key="user.id"
|
||||||
:user
|
:user
|
||||||
class="group/user flex flex-row items-center justify-between gap-4"
|
class="group/user flex flex-row items-center justify-between gap-4"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
import type { Warren } from '~/types/warrens';
|
import type { Warren } from '#shared/types/warrens';
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
middleware: ['authenticated'],
|
middleware: ['authenticated'],
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import type { AuthUser, AuthUserFields } from '~/types/auth';
|
import type { AuthUser, AuthUserFields } from '#shared/types/auth';
|
||||||
|
|
||||||
export const useAdminStore = defineStore('admin', {
|
export const useAdminStore = defineStore('admin', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
|
users: [] as AuthUser[],
|
||||||
createUserDialog: null as { user: AuthUserFields } | null,
|
createUserDialog: null as { user: AuthUserFields } | null,
|
||||||
deleteUserDialog: null as { user: AuthUser } | null,
|
deleteUserDialog: null as { user: AuthUser } | null,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import type { DirectoryEntry } from '~/types';
|
import type { DirectoryEntry } from '#shared/types';
|
||||||
import type { Warren } from '~/types/warrens';
|
import type { Warren } from '#shared/types/warrens';
|
||||||
|
|
||||||
export const useWarrenStore = defineStore('warrens', {
|
export const useWarrenStore = defineStore('warrens', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { UploadFile } from '~/types';
|
import type { UploadFile } from '#shared/types';
|
||||||
|
|
||||||
export const useUploadStore = defineStore<
|
export const useUploadStore = defineStore<
|
||||||
'warren-upload',
|
'warren-upload',
|
||||||
|
|||||||
Reference in New Issue
Block a user