mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
docs: update documentation for custom auth hooks
This commit is contained in:
@@ -5,6 +5,14 @@ import { useState, useContext, useEffect } from 'react';
|
|||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A custom hook to confirm a user's account.
|
||||||
|
*
|
||||||
|
* @returns An object with the following properties:
|
||||||
|
*
|
||||||
|
* - `needsToLogin`: A boolean indicating whether the user needs to log in.
|
||||||
|
* - `tokenInvalid`: A boolean indicating whether the token is invalid.
|
||||||
|
*/
|
||||||
const useConfirmUser = () => {
|
const useConfirmUser = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { user, mutate } = useContext(UserContext);
|
const { user, mutate } = useContext(UserContext);
|
||||||
|
|||||||
@@ -3,14 +3,10 @@ import { useRouter } from 'next/router';
|
|||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom React hook that redirects the user to the home page if they are logged in.
|
* A custom hook to redirect the user to the home page if they are logged in.
|
||||||
*
|
*
|
||||||
* This hook is used to prevent logged in users from accessing the login and signup pages
|
* This hook is used to prevent logged in users from accessing the login and signup pages
|
||||||
* by redirecting them to the home page.
|
* and should only be used in a component that is under the UserContext provider.
|
||||||
*
|
|
||||||
* This hook should only be used in a component that is under the UserContext provider.
|
|
||||||
*
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
*/
|
||||||
const useRedirectWhenLoggedIn = (): void => {
|
const useRedirectWhenLoggedIn = (): void => {
|
||||||
const { user } = useContext(UserContext);
|
const { user } = useContext(UserContext);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import APIResponseValidationSchema from '@/validation/APIResponseValidationSchem
|
|||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A custom React hook that fetches the current user's data from the server.
|
* A custom hook to fetch the current user's data.
|
||||||
*
|
*
|
||||||
* @returns An object with the following properties:
|
* @returns An object with the following properties:
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user