11import logger from "@calcom/lib/logger" ;
2- import prisma from "@calcom/prisma " ;
2+ import { CredentialRepository } from "@calcom/lib/server/repository/credential " ;
33import type { CredentialForCalendarService } from "@calcom/types/Credential" ;
44
55import { getTokenObjectFromCredential } from "./getTokenObjectFromCredential" ;
@@ -8,20 +8,10 @@ const log = logger.getSubLogger({
88 prefix : [ "getCurrentTokenObject" ] ,
99} ) ;
1010
11- async function getDelegationUserCredentialInDb ( {
12- userId,
13- delegationCredentialId,
14- } : {
15- userId : number ;
16- delegationCredentialId : string ;
17- } ) {
18- const delegationUserCredentialInDb = await prisma . credential . findFirst ( {
19- where : {
20- userId,
21- delegationCredentialId,
22- } ,
23- } ) ;
24- return delegationUserCredentialInDb ;
11+ function buildDummyTokenObjectForDelegationUserCredential ( ) {
12+ return {
13+ access_token : "TOKEN_PLACEHOLDER_FOR_DELEGATION_CREDENTIAL" ,
14+ } ;
2515}
2616
2717export async function getCurrentTokenObject (
@@ -33,16 +23,17 @@ export async function getCurrentTokenObject(
3323 log . error ( "DelegationCredential: No user id found for delegation credential" ) ;
3424 } else {
3525 log . debug ( "Getting current token object for delegation credential" ) ;
36- const delegationUserCredentialInDb = await getDelegationUserCredentialInDb ( {
37- userId : credential . userId ,
38- delegationCredentialId : credential . delegatedToId ,
39- } ) ;
26+ const delegationUserCredentialInDb =
27+ await CredentialRepository . findUniqueByUserIdAndDelegationCredentialId ( {
28+ userId : credential . userId ,
29+ delegationCredentialId : credential . delegatedToId ,
30+ } ) ;
4031 inDbCredential = delegationUserCredentialInDb ;
4132 if ( ! inDbCredential ) {
4233 log . error ( "getCurrentTokenObject: No delegation user credential found in db" ) ;
43- return {
44- access_token : "TOKEN_PLACEHOLDER_FOR_DELEGATION_CREDENTIAL" ,
45- } ;
34+ // We return a dummy token object. OAuthManager requires a token object that must have access_token.
35+ // OAuthManager will help fetching new token object and then that would be stored in DB.
36+ return buildDummyTokenObjectForDelegationUserCredential ( ) ;
4637 }
4738 }
4839 } else {
0 commit comments