我刚刚升级到firebase云功能1.0,因为没有event
参数,所以没有event.auth.variable.uid
用于提供有关当前用户的信息(虽然它没有记录)。
Firebase 1.0具有新的上下文参数,类似于
{ service: 'firebaseio.com',
name: 'projects/_/<ref>/pushId5' },
authType: 'ADMIN',
params: { pushId: 'pushId5' } }
如何在新的firebase功能sdk中获取当前用户信息?
答案 0 :(得分:2)
根据文件:
EventContext.auth
V1.0.0引入了两个新属性,用于访问触发功能的用户的用户信息,包括权限。
EventContext.auth
包含uid
和经过身份验证的用户身份验证令等信息。
EventContext.authType
包含权限级别,例如,您可以检测用户是否为管理员用户。
使用未记录的event.auth
字段的开发人员应更新任何相关代码以使用这些新属性。
因此,要获取有关用户的信息,请执行以下操作:
exports.dbWrite = functions.database.ref('/path/with/{id}').onWrite((data, context) => {
const authVar = context.auth.uid;
const authType = context.authType.ADMIN;
});
更多信息:
https://firebase.google.com/docs/functions/beta-v1-diff#sdk_changes_by_trigger_type
https://firebase.google.com/docs/reference/functions/functions.EventContext#.authType
答案 1 :(得分:1)
我的不好,而from matplotlib import pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np
##figure with two subplots and shared y-axis
fig,(ax2,ax1) = plt.subplots(nrows=1, ncols=2, sharey='row')
m1 = Basemap(llcrnrlon=-90,llcrnrlat=-58.1,urcrnrlon=-32,urcrnrlat=12.6,
#resolution='f',
projection='merc',lon_0=-58,lat_0=-25, ax=ax1)
m1.drawparallels(np.arange(-90,90.,5), labels=[0,1,0,0], linewidth=0.5)
m1.drawmeridians(np.arange(-180.,180.,5), labels=[0,0,0,1], linewidth=0.5)
m1.drawcoastlines(linewidth=0.5, color='k')
##turning off yticks at basemap
ax1.yaxis.set_ticks_position('none')
##setting yticks:
yticks = np.arange(-55,12.6,5)
##transform yticks:
_,yticks_data = m1(0*yticks,yticks)
ax2.set_yticks(yticks_data)
ax2.set_yticklabels(['{: >3}$^\circ${}'.format(
abs(int(y)), 'N' if y>0 else 'S' if y<0 else ' '
) for y in yticks])
ax2.set_xlim(120,0)
ax2.set_xlabel('Tiempo [Ma]')
ax2.set_ylabel('Latitud[$^\circ$]')
ax2.grid()
#some fake data for testing plotting
yrange = np.linspace(-60,20,100)
temp = (np.sin(10*np.deg2rad(yrange))+1)*50
##transform yrange
_,yrange_data = m1(0*yrange, yrange)
ax2.plot(temp,yrange_data)
plt.show()
中的测试功能我没有传递任何functions:shell
参数。我实际上需要像这样传递它
auth
然后可以使用myFunc(newObject, {auth: {uid: 'abcd'}})