Open hasyrails opened 3 years ago
api/hogehoge
のURLを叩いたとき、自分のidに一致するものしか見れないように実装すれば良い
current_api_user
がnilのため設定できず??
current_user and authenticate_user! returns false / devise_token_auth
current_user = User.find_by(uid: auth_headers["uid"])
cookies[:auth_headers]
でググると発見# In ApplicationController
def authenticate_current_user
head :unauthorized if get_current_user.nil?
end
def get_current_user
return nil unless cookies[:auth_headers]
auth_headers = JSON.parse cookies[:auth_headers]
expiration_datetime = DateTime.strptime(auth_headers["expiry"], "%s")
current_user = User.find_by(uid: auth_headers["uid"])
if current_user &&
current_user.tokens.has_key?(auth_headers["client"]) &&
expiration_datetime > DateTime.now
@current_user = current_user
end
@current_user
end
api/hogehoge にアクセスできない →表示もできない。
AWSのWAF で制限をかけることとする
現状
api/cards
などでURLを叩くと apiでのレコードが見ることができてしまう。→管理者にしか見れないよう実装する
ref #311