Generated file locations

By default Lucky generates files for authentication with email and password. Actions require sign in by default (set in BrowserAction), but can be configured differently by modifying these files. You can also remove feature by removing the folders. For example if you don’t want to allow sign up (maybe users are added manually or through an API), you can remove the sign_ups actions, pages, and forms

Actions and action mixins:

Forms:

Pages & Layouts:

Model, migration, and query:

Optional sign in

By default Lucky assumes most pages require sign in (apps like Gmail, SalesForce, and Dropbox). To handle this the Auth::RequireSignIn module is included in the BrowserAction.

Some apps have pages where guests can visit without sign in (Reddit, Twitter, ebay). If you have pages like that you’ll need to make a couple changes:

When the page looks very similar for signed out users

Make current_user optional in the MainLayout (src/pages/main_layout.cr):

# From this
needs current_user : User

# To this
needs current_user : User?

In your actions that don’t require sign in include the Auth::SkipRequireSignIn module:

class Users::Index < BrowserAction
  include Auth::SkipRequireSignIn

  # other code
end

To use the current_user in your pages you’ll now need check if it is nil or not:

def content
  @current_user.try do |user|
    text user.email
  end

  # or if you need an else branch
  user = @current_user
  if user
    text "Signed in as: "
    text user.email
  else
    text "Not signed in!"
  end
end

When a page looks very different

When pages look very different (different columns, sections, sidebars, etc.) it is usually best to extract a new layout.

Next: Deploying Lucky with Heroku