Skip to content

Commit b95af8d

Browse files
committed
feat(renterd-libs): add auth api
1 parent e4eac26 commit b95af8d

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

.changeset/early-rockets-count.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@siafoundation/renterd-js': minor
3+
'@siafoundation/renterd-react': minor
4+
'@siafoundation/renterd-types': minor
5+
---
6+
7+
Added the auth API.

libs/renterd-js/src/bus.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ import {
255255
AutopilotConfigUpdatePayload,
256256
AutopilotConfigUpdateResponse,
257257
busAutopilotRoute,
258+
AuthTokenPayload,
259+
AuthTokenResponse,
260+
authRoute,
261+
AuthTokenParams,
258262
} from '@siafoundation/renterd-types'
259263
import { buildRequestHandler, initAxios } from '@siafoundation/request'
260264

@@ -597,5 +601,10 @@ export function Bus({ api, password }: { api: string; password?: string }) {
597601
AutopilotConfigUpdatePayload,
598602
AutopilotConfigUpdateResponse
599603
>(axios, 'put', busAutopilotRoute),
604+
authToken: buildRequestHandler<
605+
AuthTokenParams,
606+
AuthTokenPayload,
607+
AuthTokenResponse
608+
>(axios, 'post', authRoute),
600609
}
601610
}

libs/renterd-react/src/bus.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ import {
248248
busHostHostKeyScanRoute,
249249
Host,
250250
autopilotStateRoute,
251+
AuthTokenParams,
252+
AuthTokenPayload,
253+
AuthTokenResponse,
254+
authRoute,
251255
} from '@siafoundation/renterd-types'
252256

253257
// state
@@ -1044,3 +1048,9 @@ export function useAutopilotConfigUpdate(
10441048
func()
10451049
})
10461050
}
1051+
1052+
export function useAuthToken(
1053+
args?: HookArgsCallback<AuthTokenParams, AuthTokenPayload, AuthTokenResponse>
1054+
) {
1055+
return usePostFunc({ ...args, route: authRoute })
1056+
}

libs/renterd-types/src/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,15 @@ export * from './bus'
22
export * from './autopilot'
33
export * from './worker'
44
export * from './types'
5+
6+
// Auth
7+
8+
export const authRoute = '/auth'
9+
10+
export type AuthTokenParams = {
11+
validity: number
12+
}
13+
export type AuthTokenPayload = void
14+
export type AuthTokenResponse = {
15+
token: string
16+
}

0 commit comments

Comments
 (0)