mirror of
https://github.com/rustfs/console.git
synced 2026-09-19 09:52:25 +08:00
39 lines
936 B
TypeScript
39 lines
936 B
TypeScript
import { AwsClient } from "aws4fetch"
|
|
import ApiClient from "~/lib/api-client"
|
|
|
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
const runtimeConfig = useRuntimeConfig().public
|
|
const { isAuthenticated, credentials } = useAuth()
|
|
|
|
console.log("credentials", credentials.value)
|
|
|
|
if (!isAuthenticated.value) {
|
|
return
|
|
}
|
|
|
|
const accessKeyId = credentials.value?.AccessKeyId || ""
|
|
const secretAccessKey = credentials.value?.SecretAccessKey || ""
|
|
const sessionToken = credentials.value?.SessionToken || ""
|
|
const region = runtimeConfig.s3.region || "us-east-1"
|
|
const service = "s3"
|
|
|
|
const adminApiClient = new AwsClient({
|
|
accessKeyId,
|
|
secretAccessKey,
|
|
sessionToken,
|
|
region,
|
|
service,
|
|
})
|
|
|
|
return {
|
|
provide: {
|
|
api: new ApiClient(adminApiClient, {
|
|
baseUrl: runtimeConfig.api.baseURL,
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
}),
|
|
},
|
|
}
|
|
})
|