Compare commits

..

No commits in common. "2d853b4739c20a62fc58e22949a9fc455da93948" and "469b033e2f5b00336282f85c142cc384e88c199b" have entirely different histories.

View file

@ -97,14 +97,18 @@ export async function getUserInfo(id: string) {
userInfo = userInfoCache.get(tokenInfo.owner)
else {
let userInfoRequest = await fetchUserInfo(tokenInfo.token)
console.log(`userinforequest with ${userInfoRequest.status}`)
if (!userInfoRequest.ok) {
// assume that token has expired.
// try fetching a new one
console.log("refresh token", tokenInfo.refreshToken)
if (!tokenInfo.refreshToken) return // no refresh token. back out
let token = await getNewToken({
grant_type: "refresh_token",
refresh_token: tokenInfo.refreshToken
})
console.log("new token", token)
console.log("new reftoken", token?.refresh_token)
if (!token) return // refresh failed. back out
await prisma.token.update({
where: { id },
@ -121,6 +125,7 @@ export async function getUserInfo(id: string) {
userInfo = await userInfoRequest.json()
// update user
console.log('aaa')
await prisma.user.upsert({
where: {
userId: userInfo.sub,
@ -176,6 +181,7 @@ export async function getRequestUser(request: Request, cookies: Cookies) {
// could cache this, but lazy
let userInfo = await (await fetchUserInfo(tokens.access_token)).json() as User
console.log(tokens.refresh_token)
// create a new token
let newToken = await prisma.token.create({
data: {