-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
15 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,23 @@ | ||
import { BskyAgent } from '@atproto/api' | ||
import env from '@/env/env.js' | ||
|
||
import { authLimit } from '@/env/rateLimit.js' | ||
|
||
const _agent = new BskyAgent({ service: env.LABELLER_SERVICE }) | ||
|
||
const _reauth = async (agent: BskyAgent) => { | ||
try { | ||
await authLimit( | ||
async () => | ||
await agent.login({ | ||
identifier: env.LABELLER_HANDLE, | ||
password: env.LABELLER_PASSWORD, | ||
}), | ||
) | ||
} catch (e) { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
if (!(await _reauth(_agent))) throw 'Agent Authentication Failed' | ||
await _agent.login({ | ||
identifier: env.LABELLER_HANDLE, | ||
password: env.LABELLER_PASSWORD, | ||
}) | ||
|
||
export const agentDid: string = ( | ||
await authLimit( | ||
async () => | ||
await _agent.com.atproto.identity.resolveHandle({ | ||
handle: env.LABELLER_HANDLE, | ||
}), | ||
) | ||
).data.did | ||
export const agentDid: string = `${ | ||
( | ||
await _agent.com.atproto.identity.resolveHandle({ | ||
handle: env.LABELLER_HANDLE, | ||
}) | ||
).data.did | ||
}` | ||
|
||
BskyAgent.configure({ | ||
appLabelers: [agentDid], | ||
}) | ||
|
||
export const agent: BskyAgent = _agent | ||
export const reauth = _reauth |