11import { Client } from '@atproto/lex'
22import * as dev from '#shared/types/lexicons/dev'
33import type { UriString } from '@atproto/lex'
4- import { LIKES_SCOPE } from '~~/ shared/utils/constants'
5- import { checkOAuthScope } from '~~/server/utils/atproto/oauth'
4+ import { LIKES_SCOPE } from '# shared/utils/constants'
5+ import { throwOnMissingOAuthScope } from '~~/server/utils/atproto/oauth'
66
77export default eventHandlerWithOAuthSession ( async ( event , oAuthSession ) => {
88 const loggedInUsersDid = oAuthSession ?. did . toString ( )
@@ -11,6 +11,9 @@ export default eventHandlerWithOAuthSession(async (event, oAuthSession) => {
1111 throw createError ( { statusCode : 401 , statusMessage : 'Unauthorized' } )
1212 }
1313
14+ //Checks if the user has a scope to like packages
15+ await throwOnMissingOAuthScope ( oAuthSession , LIKES_SCOPE )
16+
1417 const body = await readBody < { packageName : string } > ( event )
1518
1619 if ( ! body . packageName ) {
@@ -30,9 +33,6 @@ export default eventHandlerWithOAuthSession(async (event, oAuthSession) => {
3033 } )
3134 }
3235
33- //Checks if the user has a scope to like packages
34- await checkOAuthScope ( oAuthSession , LIKES_SCOPE )
35-
3636 const subjectRef = PACKAGE_SUBJECT_REF ( body . packageName )
3737 const client = new Client ( oAuthSession )
3838
@@ -49,5 +49,5 @@ export default eventHandlerWithOAuthSession(async (event, oAuthSession) => {
4949 } )
5050 }
5151
52- return await likesUtil . likeAPackageAndRetunLikes ( body . packageName , loggedInUsersDid , result . uri )
52+ return await likesUtil . likeAPackageAndReturnLikes ( body . packageName , loggedInUsersDid , result . uri )
5353} )
0 commit comments