├── .gitignore
├── .env
├── public
├── images
│ ├── stars-and-stripes.png
│ └── tropica-background.png
└── css
│ └── styles.css
├── CODEOWNERS
├── README.md
├── package.json
├── src
├── loginOrSignUpUtils.js
└── authenticateUtils.js
├── LICENSE
├── views
├── loggedIn.ejs
├── loginOrSignUp.ejs
└── authenticate.ejs
├── server.js
└── .github
└── workflows
└── codeql-analysis.yml
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/.env:
--------------------------------------------------------------------------------
1 | PORT='4567'
2 | STYTCH_PROJECT_ID=''
3 | STYTCH_SECRET=''
4 |
--------------------------------------------------------------------------------
/public/images/stars-and-stripes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stytchauth/stytch-node-sms/HEAD/public/images/stars-and-stripes.png
--------------------------------------------------------------------------------
/public/images/tropica-background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stytchauth/stytch-node-sms/HEAD/public/images/tropica-background.png
--------------------------------------------------------------------------------
/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # Stytch code owners file
2 |
3 | # These owners will be the default owners for everything in
4 | # the repo. Unless a later match takes precedence,
5 | # @stytchauth/client-libraries will be requested for
6 | # review when someone opens a pull request.
7 | * @stytchauth/client-libraries
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # stytch-node-sms
2 |
3 | This example app uses the [Stytch API](https://stytch.com/docs/api) to send and authenticate
4 | one-time passcodes (OTPs).
5 |
6 | ## Running the app
7 |
8 | For name continuity, create a new project called "Tropica" and use it for these setup steps. That
9 | way, the SMS message will say "Tropica verification code: xxxxxx", matching the app branding.
10 |
11 | 1. Fill in `STYTCH_PROJECT_ID` and `STYTCH_SECRET` in the `.env` file. Get your credentials from
12 | your [Stytch dashboard](https://stytch.com/dashboard/api-keys).
13 | 2. Run `npm install`
14 | 3. Run `npm start`
15 | 4. Visit `http://localhost:4567` and login by SMS passcode!
16 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "stytch-node-sms",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "server.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/stytchauth/stytch-node-magic-links.git"
12 | },
13 | "keywords": [],
14 | "author": "",
15 | "license": "ISC",
16 | "bugs": {
17 | "url": "https://github.com/stytchauth/stytch-node-magic-links/issues"
18 | },
19 | "homepage": "https://github.com/stytchauth/stytch-node-magic-links#readme",
20 | "dependencies": {
21 | "dotenv": "^8.2.0",
22 | "ejs": "^3.1.6",
23 | "express": "^4.17.1",
24 | "stytch": "^3.4.0"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/loginOrSignUpUtils.js:
--------------------------------------------------------------------------------
1 | function isValidNumber() {
2 | // Regex validates phone numbers in (xxx)xxx-xxxx, xxx-xxx-xxxx, xxxxxxxxxx, and xxx.xxx.xxxx format
3 | const regex = /^[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4}$/g;
4 | const inputValue = document.getElementById(`phoneNumber`).value;
5 | if (inputValue.match(regex)) {
6 | return true;
7 | }
8 | return false;
9 | }
10 |
11 | function onPhoneNumberChange() {
12 | // Update styling once phone number is valid.
13 | const inputs = document.getElementsByTagName('input');
14 | const button = document.getElementById('button');
15 | if (!isValidNumber()) {
16 | for (i = 0; i < inputs.length; i++) {
17 | inputs[i].style.borderColor = '#ADBCC5';
18 | button.disabled = true;
19 | }
20 | } else {
21 | for (i = 0; i < inputs.length; i++) {
22 | inputs[i].style.borderColor = '#19303D';
23 | button.disabled = false;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 stytchauth
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/views/loggedIn.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |