Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Problems with Pipe Authenticated Routes and current_user compile-time type is (User | Nil) #1030
I am using the basic authenticate pipe. I cant seem to get around errors similar to the following on authenticated actions.
Since this is an authenticated action it should be assured to be not nil. However regardless even if I try to do the following it still gives the same error.
How can I deal with this?
Looks like I fixed it with some changes to the methods in ApplicationController.
My working solution:
Maybe the solution in the docs could be updated to this. What do you think?
Hi @westonganger This is a common error you will hit using Crystal when dealing with union types.
The union type
There are several ways to do this. The one that is recommended:
if user = current_user user.fetch_items else # handle Nil type end
The assignment will remove the
Another option is to use
In Crystal, you are forced to deal with the