From ea2644119ad00d505f84b001cb265e4a70565ada Mon Sep 17 00:00:00 2001 From: Vincent Jousse Date: Tue, 15 Jun 2021 15:40:32 +0100 Subject: [PATCH] Raise an exception on failed auth --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3e22202..7a2a43c 100644 --- a/README.md +++ b/README.md @@ -63,11 +63,18 @@ module ApplicationCable # `owned_by` instruction owned_by current_user : User + def connect - UserToken.decode_user_id(token.to_s).try do |user_id| - self.identifier = user_id.to_s - self.current_user = UserQuery.find(user_id) + user_id : Int64? = UserToken.decode_user_id(token.to_s) + + # We were unable to authenticate the user, we should raise an + # unauthorized exception + if !user_id + raise UnathorizedConnectionException.new end + + self.identifier = user_id.to_s + self.current_user = UserQuery.find(user_id) end end