[英]devise_token_auth how to access user.created_at
我在Rails 5 API上使用devise_token_auth
當前,當我向/auth/sign_in
發出POST
請求時,一切順利,我得到的數據如下所示:
"data": {
"id": 3,
"email": "me@user.com",
"name": null,
"nickname": null,
"bio": null,
"description": null,
"url": null,
"image": {
"url": null
},
"provider": "email",
"uid": "me@user.com",
"allow_password_change": false,
"role": null
}
但是,我也希望能夠訪問已啟用的時間戳屬性(created_at,updated_at):
ActiveRecord::Schema.define(version: 2018_10_18_201621) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "users", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
有任何想法嗎? 提前致謝
檢查有關在github存儲庫上覆蓋devise_token_auth
gem上的渲染方法的問題討論: https : //github.com/lynndylanhurley/devise_token_auth/issues/597 。
在您的User
模型上嘗試以下代碼,以便您可以使用自定義序列化器代替默認的序列化器:
def token_validation_response
UserSerializer.root = false
UserSerializer.new(self).as_json
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.