> For the complete documentation index, see [llms.txt](https://awcrotwell.gitbook.io/mochi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://awcrotwell.gitbook.io/mochi/guides/authenticable/manual-installation.md).

# Manual Installation

1. Create `mochi.cr` in initalizers and paste this in:

   ```
    require "mochi"
   ```
2. Create a migration and paste in:

   **Granite:**

   \`\`\`sql\
   \-- +micrate Up CREATE TABLE users ( id INTEGER NOT NULL PRIMARY KEY, email VARCHAR, password\_digest VARCHAR, created\_at TIMESTAMP, updated\_at TIMESTAMP );

````
  -- +micrate Down
  DROP TABLE IF EXISTS users;
```

or

**Jennifer:**

```crystal
class CreateUser < Jennifer::Migration::Base
  def up
    create_table(:users) do |t|
      t.string :email
      t.string :password_digest
      t.timestamp :created_at
      t.timestamp :updated_at
    end
  end

  def down
    drop_table(:users)
  end
end
```
````

1. Migrate:

   **Granite:**

   ```bash
    amber db migrate
   ```

   or

   **Jennifer:**

   ```bash
    crystal sam.cr -- db:migrate
   ```
2. Create a controller titled `user_controller.cr` and paste in this file:

   [user\_controller](/mochi/guides/authenticable/controllers/user_controller.cr.md)
3. Create a controller titled `session_controller.cr` and paste in this file:

   [session\_controller](/mochi/guides/authenticable/controllers/session_controller.cr.md)
4. Add these to your routes:

   Change `pipeline :web` to `pipeline :web, :auth` and add:

   ```
    plug CurrentUser.new
   ```

   Create an `:auth` pipeline with:

   ```
    pipeline :auth do
      plug Authenticate.new
    end
   ```

   Create a new route section just for `:auth`:

   ```
    routes :auth do
      get "/profile", UserController, :show
      get "/profile/edit", UserController, :edit
      patch "/profile", UserController, :update
      get "/signout", SessionController, :delete
    end
   ```

   Add this to your `:web` routes:

   ```
    get "/signin", SessionController, :new
    post "/session", SessionController, :create
    get "/signup", UserController, :new
    post "/registration", UserController, :create
   ```
5. Create a piple titled `authenticate.cr` and paste in this file:

   [authenticate](https://github.com/sundaecr/mochi/tree/2c6c7d74cce829a080515aa79b9b40b8d7d3c859/guides/authenticable/pipes/authenticate.cr)
6. Copy & Paste all the views found here:

   [Views](https://github.com/andrewc910/mochi/tree/master/guides/authenticable/views)
7. Add a model:

   **Granite:**

   [user](/mochi/guides/authenticable/models/granite_user.cr.md)

   or

   **Jennifer:**

   [user](/mochi/guides/authenticable/models/jennifer_user.cr.md){:target="\_blank"}
8. Open `config/application.cr` and between the `# Start Generator` & `# End Generator` add:

   ```
   require "../src/models/**"
   require "../src/pipes/**"
   ```
9. Open `application_controller.cr` and add:

   ```
   def current_user
     context.current_user
   end
   ```
10. Done! And that's why we have a CLI.
