Add useCsrfToken hook and update README
A new `useCsrfToken` hook has been added for fetching CSRF token from the meta tag. The shared package's exports have been updated to include this new hook. Additionally, extensive documentation on writing server actions and API route handlers, as well as the usage of Captcha token protection and CSRF token, has been added to the README file.
This commit is contained in:
1
packages/shared/src/hooks/index.ts
Normal file
1
packages/shared/src/hooks/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './use-csrf-token';
|
||||
13
packages/shared/src/hooks/use-csrf-token.ts
Normal file
13
packages/shared/src/hooks/use-csrf-token.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Get the CSRF token from the meta tag.
|
||||
* @returns The CSRF token.
|
||||
*/
|
||||
export function useCsrfToken() {
|
||||
const meta = document.querySelector('meta[name="csrf-token"]');
|
||||
|
||||
if (!meta) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return meta.getAttribute('content') ?? '';
|
||||
}
|
||||
Reference in New Issue
Block a user