🐛 (github) remove refetch not working
This commit is contained in:
@@ -6,7 +6,7 @@ import { confirmMessage } from '@/utils/notif'
|
|||||||
import { GithubAccessToken } from '@/data/models/GithubAccessToken'
|
import { GithubAccessToken } from '@/data/models/GithubAccessToken'
|
||||||
import { Octokit } from '@octokit/rest'
|
import { Octokit } from '@octokit/rest'
|
||||||
import { GithubToken } from '@/modules/user/interfaces/GithubToken'
|
import { GithubToken } from '@/modules/user/interfaces/GithubToken'
|
||||||
import { addMilliseconds } from 'date-fns'
|
import { addSeconds } from 'date-fns'
|
||||||
|
|
||||||
const personalTokenId = 'token'
|
const personalTokenId = 'token'
|
||||||
const username = ref<string | null>(null)
|
const username = ref<string | null>(null)
|
||||||
@@ -34,12 +34,12 @@ export const useGitHubLogin = () => {
|
|||||||
const saveCredentials = async (githubToken: GithubToken) => {
|
const saveCredentials = async (githubToken: GithubToken) => {
|
||||||
const actualPAT = await getAccessToken()
|
const actualPAT = await getAccessToken()
|
||||||
|
|
||||||
const expirationDate = addMilliseconds(
|
const expirationDate = addSeconds(
|
||||||
new Date(),
|
new Date(),
|
||||||
githubToken.expires_in
|
githubToken.expires_in
|
||||||
).toISOString()
|
).toISOString()
|
||||||
|
|
||||||
const refreshTokenExpirationDate = addMilliseconds(
|
const refreshTokenExpirationDate = addSeconds(
|
||||||
new Date(),
|
new Date(),
|
||||||
githubToken.refresh_token_expires_in
|
githubToken.refresh_token_expires_in
|
||||||
).toISOString()
|
).toISOString()
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const personalTokenId = 'token'
|
|||||||
|
|
||||||
const GITHUB_URL = 'https://github.com/login/oauth/access_token'
|
const GITHUB_URL = 'https://github.com/login/oauth/access_token'
|
||||||
|
|
||||||
const refreshToken = async () => {
|
export const refreshToken = async () => {
|
||||||
const accessToken = await data.get<
|
const accessToken = await data.get<
|
||||||
DataType.GithubAccessToken,
|
DataType.GithubAccessToken,
|
||||||
GithubAccessToken
|
GithubAccessToken
|
||||||
@@ -24,8 +24,15 @@ const refreshToken = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
new Date(accessToken.expirationDate) >= new Date(),
|
||||||
|
accessToken.expirationDate,
|
||||||
|
new Date()
|
||||||
|
)
|
||||||
|
|
||||||
if (new Date(accessToken.expirationDate) >= new Date()) {
|
if (new Date(accessToken.expirationDate) >= new Date()) {
|
||||||
const response = await fetch(GITHUB_URL, {
|
const response = await fetch(GITHUB_URL, {
|
||||||
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
refresh_token: accessToken.refreshToken,
|
refresh_token: accessToken.refreshToken,
|
||||||
grant_type: 'refresh_token'
|
grant_type: 'refresh_token'
|
||||||
@@ -39,20 +46,24 @@ const refreshToken = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const expirationDate = addMilliseconds(
|
||||||
|
new Date(),
|
||||||
|
githubToken.expires_in
|
||||||
|
).toISOString()
|
||||||
|
|
||||||
|
const refreshTokenExpirationDate = addMilliseconds(
|
||||||
|
new Date(),
|
||||||
|
githubToken.refresh_token_expires_in
|
||||||
|
).toISOString()
|
||||||
|
|
||||||
const updatedAccessToken: GithubAccessToken = {
|
const updatedAccessToken: GithubAccessToken = {
|
||||||
...accessToken,
|
...accessToken,
|
||||||
token: githubToken.access_token,
|
token: githubToken.access_token,
|
||||||
expiresIn: githubToken.expires_in,
|
expiresIn: githubToken.expires_in,
|
||||||
expirationDate: addMilliseconds(
|
expirationDate,
|
||||||
new Date(),
|
|
||||||
githubToken.expires_in
|
|
||||||
).toISOString(),
|
|
||||||
refreshToken: githubToken.refresh_token,
|
refreshToken: githubToken.refresh_token,
|
||||||
refreshTokenExpiresIn: githubToken.refresh_token_expires_in,
|
refreshTokenExpiresIn: githubToken.refresh_token_expires_in,
|
||||||
refreshTokenExpirationDate: addMilliseconds(
|
refreshTokenExpirationDate
|
||||||
new Date(),
|
|
||||||
githubToken.refresh_token_expires_in
|
|
||||||
).toISOString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await data.add<DataType.GithubAccessToken>({
|
await data.add<DataType.GithubAccessToken>({
|
||||||
@@ -68,7 +79,6 @@ export const getFiles = async (
|
|||||||
if (!owner || !repo) {
|
if (!owner || !repo) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
await refreshToken()
|
|
||||||
|
|
||||||
const { accessToken } = useGitHubLogin()
|
const { accessToken } = useGitHubLogin()
|
||||||
|
|
||||||
@@ -104,7 +114,6 @@ export const getMainReadme = async (owner: string, repo: string) => {
|
|||||||
if (!owner || !repo) {
|
if (!owner || !repo) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
await refreshToken()
|
|
||||||
|
|
||||||
const { render } = useMarkdown()
|
const { render } = useMarkdown()
|
||||||
const { getCachedNote, saveCacheNote } = useNoteCache('README')
|
const { getCachedNote, saveCacheNote } = useNoteCache('README')
|
||||||
@@ -170,8 +179,6 @@ export const getFileContent = async (
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
await refreshToken()
|
|
||||||
|
|
||||||
const file = await octokit.request(
|
const file = await octokit.request(
|
||||||
'GET /repos/{owner}/{repo}/git/blobs/{file_sha}',
|
'GET /repos/{owner}/{repo}/git/blobs/{file_sha}',
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,12 +51,12 @@ export default defineComponent({
|
|||||||
|
|
||||||
.new-version {
|
.new-version {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
margin-top: 1rem;
|
top: 1rem;
|
||||||
|
right: 1rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.authorize {
|
.authorize {
|
||||||
position: absolute;
|
|
||||||
margin: auto;
|
margin: auto;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user