Skip to content

Commit 0cc7e52

Browse files
committed
enable external credentials for recommendations
1 parent f870fff commit 0cc7e52

1 file changed

Lines changed: 38 additions & 4 deletions

File tree

app/credentialImportForm/page.tsx

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { useRouter } from 'next/navigation'
1414
import VisibilityIcon from '@mui/icons-material/Visibility'
1515

1616
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'
17+
import { GoogleDriveStorage, saveToGoogleDrive } from '@cooperation/vc-storage'
18+
import { storeFileTokens } from '../firebase/storage'
1719
import { saveRaw } from '../utils/googleDrive'
1820
import {
1921
analyzeCredential,
@@ -154,6 +156,7 @@ function SimpleCredentialForm() {
154156
const { data: session } = useSession()
155157
const router = useRouter()
156158
const accessToken = session?.accessToken
159+
const refreshToken = session?.refreshToken
157160

158161
const handleUrlChange = (event: React.ChangeEvent<HTMLInputElement>) => {
159162
const inputUrl = event.target.value
@@ -313,9 +316,24 @@ function SimpleCredentialForm() {
313316
if (vcData.type?.includes('VerifiablePresentation') && vcData.verifiableCredential?.[0]) {
314317
credentialToSave = vcData.verifiableCredential[0]
315318
}
316-
317-
const savedFile = await saveRaw(accessToken, credentialToSave)
318-
console.log('External credential saved to Google Drive:', savedFile)
319+
320+
console.log('trying to save ext credential: ', credentialToSave)
321+
const storage = new GoogleDriveStorage(accessToken)
322+
const savedFile = await saveToGoogleDrive({storage, data:credentialToSave, type:'VC'})
323+
try{
324+
await storeFileTokens({
325+
googleFileId: savedFile.id,
326+
tokens: {
327+
accessToken: accessToken,
328+
refreshToken: refreshToken as string
329+
}
330+
})
331+
console.log('External credential saved to Google Drive:', savedFile)
332+
} catch {
333+
console.log("Cannot seem to save the file or the tokens")
334+
}
335+
336+
//const savedFile = await saveRaw(accessToken, credentialToSave)
319337

320338
setFetchResult({
321339
success: true,
@@ -361,7 +379,23 @@ function SimpleCredentialForm() {
361379
// Save the credential directly to Google Drive
362380
if (accessToken) {
363381
try {
364-
const savedFile = await saveRaw(accessToken, vcData)
382+
383+
const storage = new GoogleDriveStorage(accessToken)
384+
const savedFile = await saveToGoogleDrive({storage, data:vcData, type:'VC'})
385+
try{
386+
await storeFileTokens({
387+
googleFileId: savedFile.id,
388+
tokens: {
389+
accessToken: accessToken,
390+
refreshToken: refreshToken as string
391+
}
392+
})
393+
console.log('External credential saved to Google Drive:', savedFile)
394+
} catch {
395+
console.log("Cannot seem to save the file or the tokens")
396+
}
397+
398+
//const savedFile = await saveRaw(accessToken, vcData)
365399
console.log('Credential saved to Google Drive:', savedFile)
366400
} catch (saveError) {
367401
console.error('Error saving to Google Drive:', saveError)

0 commit comments

Comments
 (0)