V2云函数类型接口中的UserRecord(Contex)等价物是什么?

问题描述 投票:0回答:1

我正在尝试输入我的 fucntinos,但在新 api 中找不到类型防御,知道接口的新名称是什么吗?

这个可以吗

type AuthType =functionsHttps.CallableRequest['auth'];

相当于

从 'firebase-functions/v1/auth' 导入 { UserRecord };

因为我无法在 /v2 中找到类型

interface Request {
  data: CreateUserData; // local interface 
  auth?: any; // UserRecord in V1
}

// Documentation: V2 Create Data Functions with custom claims.
export const createUserV2 = functionsHttps.onCall(async (request: Request) => {
  const uid = request.auth?.uid;
  const authData = request.auth;
  const { userType, privacySettings } = request.data;
  
  // rest of the codde
})

google-cloud-functions
1个回答
0
投票

您没有正确输入请求对象。 v2 可调用函数的第一个参数是一个 CallableRequest 对象(不是现在的 Request 对象)。

您要查找的使用信息已在 文档中使用示例进行了介绍(假设您输入正确):

// Authentication / user information is automatically added to the request.
const uid = request.auth.uid;
const name = request.auth.token.name || null;
const picture = request.auth.token.picture || null;
const email = request.auth.token.email || null;
© www.soinside.com 2019 - 2024. All rights reserved.