@authhero/锯齿适应器
AWS DynamoDB为AuthHero的适配器. 这个适配器执行AuthHero数据适配器,使用Amazon DynamoDB作为存储后端.
特征
- 用于高效使用DynamomaDB的单表设计
- 与AWS Lambda和Cloudflare工人合作
- 具有完整类型脚本支持的类型安全
安装
npm install @authhero/aws-adapter
# or
pnpm add @authhero/aws-adapter
使用量
与 AWS 蓝巴达
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
import createAdapters from "@authhero/aws-adapter";
const client = new DynamoDBClient({});
const docClient = DynamoDBDocumentClient.from(client);
const adapters = createAdapters(docClient, {
tableName: "authhero",
});
和云花岗工人
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
import createAdapters from "@authhero/aws-adapter";
// In Cloudflare Workers, you need to provide credentials explicitly
const client = new DynamoDBClient({
region: env.AWS_REGION,
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY,
},
});
const docClient = DynamoDBDocumentClient.from(client);
const adapters = createAdapters(docClient, {
tableName: "authhero",
});
表格设计
此适配器采用单表设计,并有以下关键结构: 1
| 实体 | PK 键 | 苏格兰 |
|---|---|---|
| 租户 | TENANT#{tenant_id} | TENANT |
| 用户 | TENANT#{tenant_id} | USER#{user_id} |
| 会议 | TENANT#{tenant_id} | SESSION#{session_id} |
| 客户端 | TENANT#{tenant_id} | CLIENT#{client_id} |
| 连接 | TENANT#{tenant_id} | CONNECTION#{connection_id} |
| 代码 | TENANT#{tenant_id} | CODE#{code_id} |
| 密码 | TENANT#{tenant_id}#USER#{user_id} | PASSWORD#{password_id} |
| . | . | . |
全球二级指数
-
GSI1 (英语): 供用户通过电子邮件查询
- GSI1PK: (英语)
TENANT#{tenant_id}#EMAIL#{email} - GSI1SK: (英语)
USER
- GSI1PK: (英语)
-
GSI2 (英语):用于查询自定义域
- GSI2PK: (英语)
DOMAIN#{domain} - GSI2SK: (英语)
CUSTOM_DOMAIN
- GSI2PK: (英语)
DynamoDB 表格设置
创建带有以下配置的 DynamomDB 表格 :
{
"TableName": "authhero",
"KeySchema": [
{ "AttributeName": "PK", "KeyType": "HASH" },
{ "AttributeName": "SK", "KeyType": "RANGE" }
],
"AttributeDefinitions": [
{ "AttributeName": "PK", "AttributeType": "S" },
{ "AttributeName": "SK", "AttributeType": "S" },
{ "AttributeName": "GSI1PK", "AttributeType": "S" },
{ "AttributeName": "GSI1SK", "AttributeType": "S" },
{ "AttributeName": "GSI2PK", "AttributeType": "S" },
{ "AttributeName": "GSI2SK", "AttributeType": "S" }
],
"GlobalSecondaryIndexes": [
{
"IndexName": "GSI1",
"KeySchema": [
{ "AttributeName": "GSI1PK", "KeyType": "HASH" },
{ "AttributeName": "GSI1SK", "KeyType": "RANGE" }
],
"Projection": { "ProjectionType": "ALL" }
},
{
"IndexName": "GSI2",
"KeySchema": [
{ "AttributeName": "GSI2PK", "KeyType": "HASH" },
{ "AttributeName": "GSI2SK", "KeyType": "RANGE" }
],
"Projection": { "ProjectionType": "ALL" }
}
],
"BillingMode": "PAY_PER_REQUEST"
}
许可证
麻省理工学院