# 型別

本頁列出套件匯出的全部 TypeScript 介面。

## AuthData

簽入 Token 與存進 Refresh 資料的使用者資料。

```typescript
interface AuthData {
  id: string;
  name: string;
  email: string;
  thumbnail?: string;
  level?: number;
  role?: string;
  scope?: string[];
}
```

`id` 會傳給 `checkUserExists()`。整個物件會序列化存入 Redis，續期後原樣作為 `VerifyResult.data` 回傳。

## VerifyResult

`VerifyJWT()` 的回傳值，三個旗標的意義見[驗證結果](/zh/verify-results)。

```typescript
interface VerifyResult {
  data?: AuthData;
  isAuth: boolean;
  isError: boolean;
  isGuest: boolean;
}
```

## TokenResult

`CreateJWT()` 的回傳值。

```typescript
interface TokenResult {
  token: string;
  refresh_id: string;
}
```

## RefreshData

存於 `refresh:<refresh_id>` 的 JSON 結構。

```typescript
interface RefreshData {
  data: AuthData;
  version: number;
  fp: string;
  expires_at: Date;
  issued_at: Date;
}
```

## JWTPayload

Access Token 解碼後的欄位：`AuthData` 加上 `fp` 與 `refresh_id`。續期簽發的 Token 另含 `version`。

```typescript
interface JWTPayload {
  id: string;
  name: string;
  email: string;
  thumbnail?: string;
  level?: number;
  role?: string;
  scope?: string[];
  fp: string;
  refresh_id: string;
}
```

## Config

`init()` 的參數，每個欄位的說明與預設值見[設定](/zh/configuration)。

```typescript
interface Config {
  publicKeyPath?: string;
  privateKeyPath?: string;
  publicKey?: string;
  privateKey?: string;
  accessTokenExpires: number;
  refreshTokenExpires: number;
  isProd: boolean;
  domain?: string;
  redis: {
    host: string;
    port: number;
    password?: string;
    db?: number;
  };
  checkUserExists: (userId: string) => Promise<boolean>;
  AccessTokenCookieKey: string;
  RefreshTokenCookieKey: string;
}
```
