mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-07-26 21:51:46 +00:00
Extract useGoogleAuth from app.tsx
This commit is contained in:
19
src/hooks/use_google_auth.ts
Normal file
19
src/hooks/use_google_auth.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import {useState} from 'react';
|
||||
import {googleDriveService} from '../datasource/google_drive_service';
|
||||
|
||||
/**
|
||||
* Custom React hook to manage and track the state of Google Drive OAuth2 credentials.
|
||||
*/
|
||||
export function useGoogleAuth() {
|
||||
/** Tracks whether the user has a valid cached Google Drive OAuth access token. */
|
||||
const [hasGoogleToken, setHasGoogleToken] = useState(
|
||||
() => !!googleDriveService.getAccessToken(),
|
||||
);
|
||||
|
||||
return {
|
||||
/** Tracks whether the user has a valid cached Google Drive OAuth access token. */
|
||||
hasGoogleToken,
|
||||
/** Function to update the token presence state in React. */
|
||||
setHasGoogleToken,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user