-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GIST-56): add refresh token mechanism
- Loading branch information
1 parent
5131611
commit adb8a0e
Showing
6 changed files
with
138 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,65 @@ | ||
'use client' | ||
|
||
import { ReactNode, useCallback } from 'react' | ||
import GistLayout from './layout-ui' | ||
import { useMe } from '@/lib/queries/user.queries' | ||
import { useToast } from '@/components/shadcn/use-toast' | ||
import { useCreateGist } from '@/lib/queries/gists.queries' | ||
import { useCreateOrg } from '@/lib/queries/orgs.queries' | ||
|
||
export default function GistLayoutFeature({ children }: { children: ReactNode }) { | ||
const { data } = useMe() | ||
const { toast } = useToast() | ||
"use client"; | ||
|
||
import { ReactNode, useCallback } from "react"; | ||
import GistLayout from "./layout-ui"; | ||
import { useMe } from "@/lib/queries/user.queries"; | ||
import { useToast } from "@/components/shadcn/use-toast"; | ||
import { useCreateGist } from "@/lib/queries/gists.queries"; | ||
import { useCreateOrg } from "@/lib/queries/orgs.queries"; | ||
|
||
export default function GistLayoutFeature({ | ||
children, | ||
}: { | ||
children: ReactNode; | ||
}) { | ||
const { data, error } = useMe(); | ||
const { toast } = useToast(); | ||
const { mutate: createGist } = useCreateGist({ | ||
onSuccess: () => { | ||
toast({ | ||
title: 'Gist Created', | ||
description: 'Your gist has been created successfully', | ||
}) | ||
title: "Gist Created", | ||
description: "Your gist has been created successfully", | ||
}); | ||
}, | ||
}) | ||
}); | ||
|
||
const { mutate: createTeam } = useCreateOrg({ | ||
onSuccess: () => { | ||
toast({ | ||
title: 'Team Created', | ||
description: 'Your team has been created successfully', | ||
}) | ||
title: "Team Created", | ||
description: "Your team has been created successfully", | ||
}); | ||
}, | ||
}) | ||
}); | ||
|
||
const onMyGistsClick = () => { | ||
} | ||
const onMyGistsClick = () => {}; | ||
|
||
const onCreateTeamClick = useCallback( | ||
(name: string) => { | ||
createTeam(name) | ||
createTeam(name); | ||
}, | ||
[toast, createTeam] | ||
) | ||
[toast, createTeam], | ||
); | ||
|
||
const onLogoutClick = () => { | ||
} | ||
const onLogoutClick = () => {}; | ||
|
||
const onCreateGistClick = (name: string, content: string) => { | ||
createGist({ | ||
content, | ||
name, | ||
}) | ||
} | ||
}); | ||
}; | ||
|
||
return ( | ||
<GistLayout | ||
onLogoutClick={onLogoutClick} | ||
username={data?.name ?? ''} | ||
avatar={data?.picture ?? ''} | ||
username={data?.name ?? ""} | ||
avatar={data?.picture ?? ""} | ||
onCreateTeamClick={onCreateTeamClick} | ||
onMyGistsClick={onMyGistsClick} | ||
onCreateGistClick={onCreateGistClick} | ||
> | ||
{children} | ||
</GistLayout> | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
"use client"; | ||
import { QueryClient } from "@tanstack/react-query"; | ||
import { cache } from "react"; | ||
import { toast } from "@/components/shadcn/use-toast"; | ||
import { QueryCache, QueryClient } from "@tanstack/react-query"; | ||
import { renewToken } from "./auth.queries"; | ||
|
||
export const getQueryClient = () => { | ||
return new QueryClient(); | ||
return new QueryClient({ | ||
queryCache: new QueryCache({ | ||
onError: async (error, query) => { | ||
if (error.message.includes("401")) { | ||
try { | ||
await renewToken(); | ||
query.fetch(); //try to refetch | ||
} catch { | ||
// need to logout !!!! | ||
toast({ | ||
title: "Error", | ||
description: "Please try to log in again", | ||
}); | ||
} | ||
} | ||
}, | ||
}), | ||
}); | ||
}; | ||
export default getQueryClient; |