mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-08 22:53:25 +00:00
feat: add user token management
This commit is contained in:
33
inertia/hooks/use_api_tokens.ts
Normal file
33
inertia/hooks/use_api_tokens.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { router, usePage } from '@inertiajs/react';
|
||||
|
||||
interface ApiToken {
|
||||
id: number;
|
||||
name: string;
|
||||
token: string;
|
||||
lastUsedAt: string | null;
|
||||
expiresAt: string | null;
|
||||
isActive: boolean;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export function useApiTokens() {
|
||||
const {
|
||||
props: { tokens },
|
||||
} = usePage<{
|
||||
tokens: ApiToken[];
|
||||
}>();
|
||||
|
||||
const createToken = async (name: string, expiresAt?: Date) => {
|
||||
return router.post('/user/api-tokens', { name, expiresAt });
|
||||
};
|
||||
|
||||
const revokeToken = async (tokenId: number) => {
|
||||
return router.delete(`/user/api-tokens/${tokenId}`);
|
||||
};
|
||||
|
||||
return {
|
||||
tokens,
|
||||
createToken,
|
||||
revokeToken,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user