|
1 | | -# create-svelte |
| 1 | +# SvelteKit Authentication Example |
2 | 2 |
|
3 | | -Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte). |
| 3 | +This is an example of how tow to sign up, sing in, authenticate, send PIN code mai, sign in with Google and sign in with Twitter. |
4 | 4 |
|
5 | | -## Creating a project |
| 5 | +## Sign up |
6 | 6 |
|
7 | | -If you're seeing this, you've probably already done this step. Congrats! |
| 7 | +This project does not have a sign up process. If the account does not exist in the database when you sign in, it will be created automatically. |
| 8 | + |
| 9 | +## Sign in |
| 10 | + |
| 11 | +You can sign in with only your email address and PIN code. To confirm your email address, this project will email you a PIN code. |
| 12 | +You can also sign in with Google and sign in with Twitter. |
| 13 | + |
| 14 | +1. Local accounts via email |
| 15 | +2. Sign in with Google |
| 16 | +3. Sign in with Twitter |
| 17 | + |
| 18 | +## Prerequisites |
| 19 | + |
| 20 | +- [MySQL Community Server 8.0.30](https://dev.mysql.com/downloads/mysql/) or higher |
| 21 | +- [Node.js](https://nodejs.org/) 18.4.0 or higher |
| 22 | +- npm 8.13.2 or higher |
| 23 | +- Gmail account for sendmail |
| 24 | + |
| 25 | +### Prerequisites for signing in with Google (option) |
| 26 | + |
| 27 | +- [Google API client ID and setup](https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid) |
| 28 | + |
| 29 | +### Prerequisites for signing in with Twitter (option) |
| 30 | + |
| 31 | +- [Twitter developer account and setup](https://developer.twitter.com/en/docs/apps/overview) |
| 32 | + |
| 33 | +## Setting up the Gmail for sending PIN code emails |
| 34 | + |
| 35 | +1. Visit [Google Account - Security](https://myaccount.google.com/security) |
| 36 | +1. Turn on 2-Step Verification |
| 37 | +1. Create an app password |
| 38 | + |
| 39 | +## Setting up the project |
| 40 | + |
| 41 | +Here are the steps: |
| 42 | + |
| 43 | +1. Get the project and setup: |
8 | 44 |
|
9 | 45 | ```bash |
10 | | -# create a new project in the current directory |
11 | | -npm create svelte@latest |
| 46 | +# Clone the repo to your current directory |
| 47 | +git clone https://github.com/sinProject-Inc/sveltekit_authentication_example.git |
12 | 48 |
|
13 | | -# create a new project in my-app |
14 | | -npm create svelte@latest my-app |
| 49 | +# Install the dependencies |
| 50 | +cd /sveltekit_authentication_example |
| 51 | +npm install |
15 | 52 | ``` |
16 | 53 |
|
17 | | -## Developing |
| 54 | +2. Create a database named sveltekit_authentication |
| 55 | +3. Create a .env file by copying .env.example at the top level of the project |
| 56 | +4. rewrite the env file: |
18 | 57 |
|
19 | | -Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: |
| 58 | +```env |
| 59 | +DATABASE_URL="mysql://user:password@localhost:3306/sveltekit_authentication" |
20 | 60 |
|
21 | | -```bash |
22 | | -npm run dev |
| 61 | +GMAIL_USER="username@gmail.com" |
| 62 | +GMAIL_PASS="google_app_password" |
23 | 63 |
|
24 | | -# or start the server and open the app in a new browser tab |
25 | | -npm run dev -- --open |
| 64 | +TWITTER_CLIENT_ID="(option)" |
| 65 | +TWITTER_CLIENT_SECRET="(option)" |
26 | 66 | ``` |
27 | 67 |
|
28 | | -## Building |
| 68 | +5. Push the initial schema to the database: |
| 69 | + |
| 70 | +```bash |
| 71 | +npx prisma db push |
| 72 | +``` |
29 | 73 |
|
30 | | -To create a production version of your app: |
| 74 | +## Run locally |
31 | 75 |
|
32 | 76 | ```bash |
33 | | -npm run build |
| 77 | +# Start the server and open the app in a new browser tab |
| 78 | +npm run dev -- --open |
34 | 79 | ``` |
35 | 80 |
|
36 | | -You can preview the production build with `npm run preview`. |
| 81 | +## Set initial data only for the first time |
| 82 | + |
| 83 | +Write Roles and Lifetime settings: |
| 84 | + |
| 85 | +visit http://localhost:5173/initialize_database |
| 86 | + |
| 87 | +## How to sign in |
| 88 | + |
| 89 | +1. visit sign in page |
| 90 | +2. Enter your email address |
| 91 | +3. Check your email for PIN code |
| 92 | +4. Enter PIN code |
| 93 | + |
| 94 | +## My ask of you |
37 | 95 |
|
38 | | -> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. |
| 96 | +Please report any issues [here](https://github.com/sinProject-Inc/sveltekit_authentication_example/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc). [Pull requests](https://github.com/sinProject-Inc/sveltekit_authentication_example/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc) are encouraged especially as SvelteKit is evolving rapidly. |
0 commit comments