{"title":"Amber Auth","description":"","section":"examples","version":"v1.5","path":"examples/amber-auth","canonical_url":"https://amberframework.org/docs/v1.5/examples/amber-auth","markdown_url":"https://amberframework.org/docs/v1.5/examples/amber-auth.md","inherited":true,"content_markdown":"# Amber Auth\n\n**Prerequisites**\n\n* Familiar with MVC and terms such as Migrations, Database\n* Amber Framework CLI already installed \\([Installation Instructions](../guides/installation.md)\\)\n* Terminal console\n\n## Overview\n\nVirtually all web applications require a registering and authenticating users. As a result, most web frameworks have an excessive amount of options for implementing authentication. Amber Framework differs by providing a built-in generator for simple yet secure authentication that is sufficient yet easily extended at a later time. Amber allows you to get started writing your application without getting bogged down in application boilerplate.\n\n## Using Amber Auth Generator\n\n### 1. Generate Blogsy App\n\nFirst, we generate our app by typing the following command in a terminal console.\n\n```bash\namber new blogsy --deps -d sqlite\n```\n\n{% hint style=\"info\" %}\nThe `--deps` will automatically install project dependencies. `-d sqlite` builds the project with a SQLite database.\n{% endhint %}\n\n### 2. Go to your project directory\n\nCommands are performed within the root directory of our project.\n\n```bash\ncd blogsy\n```\n\n### 3. Scaffold the User Authentication\n\nNext, we will scaffold our authentication system. The scaffold will generate several files to build a basic authentication system.\n\n```bash\namber g auth User\n```\n\nThe above command will give you the following output:\n\n```text\n08:26:45 Generate    | Rendering Auth user\n08:26:45 Generate    | new       config/initializers/granite.cr\n08:26:45 Generate    | new       spec/models/user_spec.cr\n08:26:45 Generate    | new       spec/models/spec_helper.cr\n08:26:45 Generate    | new       spec/controllers/spec_helper.cr\n08:26:45 Generate    | new       db/migrations/20180110202645523_create_user.sql\n08:26:45 Generate    | new       db/seeds.cr\n08:26:45 Generate    | new       src/models/user.cr\n08:26:45 Generate    | new       src/controllers/registration_controller.cr\n08:26:45 Generate    | new       src/controllers/user_controller.cr\n08:26:45 Generate    | new       src/controllers/session_controller.cr\n08:26:45 Generate    | new       src/views/registration/new.slang\n08:26:45 Generate    | rewritten src/views/layouts/_nav.slang\n08:26:45 Generate    | new       src/views/user/show.slang\n08:26:45 Generate    | new       src/views/user/edit.slang\n08:26:45 Generate    | new       src/views/session/new.slang\n08:26:45 Generate    | new       src/handlers/authenticate.cr\n```\n\nTo finalize installing the generated authentication system, we have to migrate the database.\n\n```text\namber db create migrate\n```\n\n```text\n08:52:25 (INFO) Database    | Created database blogsy_development\n08:52:25 (INFO) Database    | Migrating db, current version: 0, target: 20180110205213147\n08:52:25 (INFO) Database    | OK   20180110205213147_create_user.sql\n```\n\nNow we can run our local development server and see our working authentication system.\n\n```text\namber watch\n```\n\n```text\n08:53:52 Watcher    | Terminating app Blogsy...\n08:53:52 Watcher    | Compiling Blogsy...\n08:53:52 Watcher    | Building project Blogsy...\n08:54:05 Server     | [Amber 0.6.1] serving application \"Blogsy\" at http://0.0.0.0:3000\n08:54:05 Server     | Server started in development.\n08:54:05 Server     | Startup Time 00:00:00.000596000\n```\n\n### 4. Sign up and Sign in Pages\n\nTo see the signup page visit [http://0.0.0.0:3000/signup](http://0.0.0.0:3000/signup)\n\n## Recap\n\nAmber framework provides an authentication system generator that allows you to focus on build your application rather than implementation details. The built-in authentication generator is not a full-featured authentication system, it provides the basic framework and can be extended as needed."}