@intrasoft/auth-next
Version:
A robust and customizable authentication package for Next.js app (router) applications, providing JWT-based authentication and token management
72 lines (62 loc) • 2.45 kB
TypeScript
import React from 'react';
/**
* Authenticates a user by checking their cookies and tokens.
*
* @returns {Promise<T>} The authenticated user object.
* @throws {Error} If the user is not authenticated or if the tokens cannot be re-fetched.
*
* @example
* ```typescript
* const user = await auth<User>();
* console.log(user);
* ```
*/
declare function auth<T = any>(): Promise<T>;
declare function useAuth(): {
user: null;
};
declare const index$1_useAuth: typeof useAuth;
declare namespace index$1 {
export { index$1_useAuth as useAuth };
}
type Props$1 = {
redirectUrl?: string;
children: React.ReactNode;
};
declare function SignIn(props: Props$1): Promise<React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | (string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined)>;
type Props = {
redirectUrl?: string;
children: React.ReactNode;
};
declare function SignOut(props: Props): Promise<React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | (string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined)>;
declare const index_SignIn: typeof SignIn;
declare const index_SignOut: typeof SignOut;
declare namespace index {
export { index_SignIn as SignIn, index_SignOut as SignOut };
}
/**
* Retrieves the current authenticated user.
*
* @returns {Promise<any>} A promise that resolves to the current authenticated user.
*/
declare function getCurrentUser(): Promise<any>;
/**
* Logs out the current authenticated user.
*
* @param {any} payload - The payload sign and authenticate
* @returns {Promise<void>}
*/
declare function loginUser(payload: any): Promise<void>;
/**
* Logs out the current authenticated user.
*
* @returns {Promise<void>}
*/
declare function logoutUser(): Promise<void>;
declare const actions_getCurrentUser: typeof getCurrentUser;
declare const actions_loginUser: typeof loginUser;
declare const actions_logoutUser: typeof logoutUser;
declare namespace actions {
export { actions_getCurrentUser as getCurrentUser, actions_loginUser as loginUser, actions_logoutUser as logoutUser };
}
export { actions, auth, index$1 as client, index as server };