Skip to content

Commit 76e57a6

Browse files
committed
Initial commit
0 parents  commit 76e57a6

16 files changed

+446
-0
lines changed

.eslintrc.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable unicorn/prefer-module */
2+
module.exports = {
3+
root: true,
4+
parser: "@typescript-eslint/parser",
5+
plugins: ["@typescript-eslint", "unicorn", "jest", "prettier"],
6+
extends: [
7+
"plugin:unicorn/recommended",
8+
"plugin:@typescript-eslint/recommended",
9+
"plugin:prettier/recommended",
10+
],
11+
rules: {
12+
"prefer-const": "off",
13+
"@typescript-eslint/explicit-module-boundary-types": "off",
14+
"@typescript-eslint/no-non-null-assertion": "off",
15+
"no-unused-vars": "off",
16+
"no-var": "off",
17+
"unicorn/no-null": "off",
18+
"unicorn/prefer-node-protocol": "off",
19+
"unicorn/filename-case": "off",
20+
"unicorn/prevent-abbreviations": "off",
21+
},
22+
};

.github/release.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
changelog:
2+
categories:
3+
- title: Documentation Changes
4+
labels:
5+
- documentation
6+
- title: New Features
7+
labels:
8+
- enhancement
9+
- title: Bug Fixes
10+
labels:
11+
- bug
12+
- title: Other Changes
13+
labels:
14+
- "*"

.github/workflows/bump.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Bump version
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Type of version (major / minor / patch)'
8+
required: true
9+
10+
jobs:
11+
bump-version:
12+
name: Bump version
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check out source
16+
uses: actions/checkout@v2
17+
with:
18+
ssh-key: ${{ secrets.DEPLOY_KEY }}
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v2
21+
with:
22+
node-version: '16'
23+
cache: 'npm'
24+
- name: Install dependencies
25+
uses: bahmutov/npm-install@v1
26+
- name: Setup Git
27+
run: |
28+
git config user.name '${{ secrets.GIT_USER_NAME }}'
29+
git config user.email '${{ secrets.GIT_USER_EMAIL }}'
30+
- name: bump version
31+
run: npm version ${{ github.event.inputs.version }}
32+
33+
- name: Push latest version
34+
run: git push origin main --follow-tags

.github/workflows/main.yml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
name: Build
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout repo
11+
uses: actions/checkout@v2
12+
13+
- name: Use Node 14
14+
uses: actions/setup-node@v1
15+
with:
16+
node-version: 14
17+
18+
- name: Install dependencies
19+
uses: bahmutov/npm-install@v1
20+
21+
- name: Build
22+
run: npm run build
23+
24+
typecheck:
25+
name: Typechecker
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout repo
29+
uses: actions/checkout@v2
30+
31+
- name: Use Node 14
32+
uses: actions/setup-node@v1
33+
with:
34+
node-version: 14
35+
36+
- name: Install dependencies
37+
uses: bahmutov/npm-install@v1
38+
39+
- name: Typecheck
40+
run: npm run typecheck
41+
42+
test:
43+
name: Unit and Integration Tests
44+
runs-on: ubuntu-latest
45+
steps:
46+
- name: Checkout repo
47+
uses: actions/checkout@v2
48+
49+
- name: Use Node 14
50+
uses: actions/setup-node@v1
51+
with:
52+
node-version: 14
53+
54+
- name: Install dependencies
55+
uses: bahmutov/npm-install@v1
56+
57+
- name: Test
58+
run: npm run test -- --ci --coverage --maxWorkers=2
59+
60+
lint:
61+
name: Linter
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Checkout repo
65+
uses: actions/checkout@v2
66+
67+
- name: Use Node 14
68+
uses: actions/setup-node@v1
69+
with:
70+
node-version: 14
71+
72+
- name: Install dependencies
73+
uses: bahmutov/npm-install@v1
74+
75+
- name: Build
76+
run: npm run build
77+
78+
- name: Lint
79+
run: npm run lint

.github/workflows/publish.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v1
12+
- uses: actions/setup-node@v1
13+
with:
14+
node-version: 14
15+
registry-url: https://registry.npmjs.org/
16+
- run: npm install
17+
- run: npm run build
18+
- run: npm publish --access public
19+
env:
20+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/node_modules
2+
/build
3+
/coverage
4+
5+
*.log
6+
.DS_Store

CONTRIBUTING.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Contribution
2+
3+
## Setup
4+
5+
Run `npm install` to install the dependencies.
6+
7+
Run the tests with `npm run test`.
8+
9+
Run the linter with `npm run lint`.
10+
11+
Run the typechecker with `npm run typecheck`.

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Sergio Xalambrí
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.

README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Remix Auth - Strategy Template
2+
3+
> A template for creating a new Remix Auth strategy.
4+
5+
If you want to create a new strategy for Remix Auth, you could use this as a template for your repository.
6+
7+
The repo installs the latest version of Remix Auth and do the setup for you to have tests, linting and typechecking.
8+
9+
## How to use it
10+
11+
1. In the `package.json` change `name` to your strategy name, also add a description and ideally an author, repository and homepage keys.
12+
2. In `src/index.ts` change the `MyStrategy` for the strategy name you want to use.
13+
3. Implement the strategy flow inside the `authenticate` method. Use `this.success` and `this.failure` to correctly send finish the flow.
14+
4. In `tests/index.test.ts` change the tests to use your strategy and test it. Inside the tests you have access to `jest-fetch-mock` to mock any fetch you may need to do.
15+
5. Once you are ready, set the secrets on Github
16+
- `NPM_TOKEN`: The token for the npm registry
17+
- `GIT_USER_NAME`: The you want the bump workflow to use in the commit.
18+
- `GIT_USER_EMAIL`: The email you want the bump workflow to use in the commit.
19+
20+
## Scripts
21+
22+
- `build`: Build the project for production using the TypeScript compiler (strips the types).
23+
- `typecheck`: Check the project for type errors, this also happens in build but it's useful to do in development.
24+
- `lint`: Runs ESLint againt the source codebase to ensure it pass the linting rules.
25+
- `test`: Runs all the test using Jest.
26+
27+
## Documentations
28+
29+
To facilitate creating a documentation for your strategy, you can use the following Markdown
30+
31+
```markdown
32+
# Strategy Name
33+
34+
<!-- Description -->
35+
36+
## Supported runtimes
37+
38+
| Runtime | Has Support |
39+
| ---------- | ----------- |
40+
| Node.js | ✅ |
41+
| Cloudflare | ✅ |
42+
43+
<!-- If it doesn't support one runtime, explain here why -->
44+
45+
## How to use
46+
47+
<!-- Explain how to use the strategy, here you should tell what options it expects from the developer when instantiating the strategy -->
48+
```

config/jest.config.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Config } from "@jest/types";
2+
// eslint-disable-next-line unicorn/prefer-node-protocol
3+
// eslint-disable-next-line unicorn/import-style
4+
import * as path from "path";
5+
6+
const config: Config.InitialOptions = {
7+
verbose: Boolean(process.env.CI),
8+
rootDir: path.resolve("."),
9+
collectCoverageFrom: ["<rootDir>/src/**/*.ts"],
10+
setupFilesAfterEnv: ["<rootDir>/config/jest/setup.ts"],
11+
testMatch: ["<rootDir>/test/**/*.test.ts"],
12+
transform: {
13+
"\\.[jt]sx?$": [
14+
"babel-jest",
15+
{ configFile: "./config/jest/babel.config.js" },
16+
],
17+
},
18+
};
19+
20+
export default config;

config/jest/babel.config.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* This Babel configuration is not being used by Remix to compiler our app.
3+
* The reason to configure Babel in our project is because Jest needs this
4+
* file to support JSX and TypeScript. This is also the reason why the
5+
* preset-env targets is only the current version of Node.js
6+
*/
7+
/* eslint-disable unicorn/prefer-module */
8+
module.exports = {
9+
presets: [
10+
[
11+
"@babel/preset-env",
12+
{
13+
targets: { node: "current" },
14+
},
15+
],
16+
[
17+
"@babel/preset-react",
18+
{
19+
runtime: "automatic",
20+
},
21+
],
22+
"@babel/preset-typescript",
23+
],
24+
};

config/jest/setup.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { installGlobals } from "@remix-run/node";
2+
import "jest-fetch-mock/setupJest";
3+
4+
installGlobals();

package.json

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "remix-auth-strategy-template",
3+
"version": "0.0.0",
4+
"main": "./build/index.js",
5+
"types": "./build/index.d.ts",
6+
"scripts": {
7+
"build": "tsc --project tsconfig.json",
8+
"typecheck": "tsc --project tsconfig.json --noEmit",
9+
"lint": "eslint --ext .ts,.tsx src/",
10+
"test": "jest --config=config/jest.config.ts --passWithNoTests",
11+
"coverage": "npm run test -- --coverage"
12+
},
13+
"keywords": [
14+
"remix",
15+
"remix-auth",
16+
"auth",
17+
"authentication",
18+
"strategy"
19+
],
20+
"license": "MIT",
21+
"files": [
22+
"build",
23+
"package.json",
24+
"README.md"
25+
],
26+
"peerDependencies": {
27+
"@remix-run/server-runtime": "^1.0.0"
28+
},
29+
"devDependencies": {
30+
"@babel/core": "^7.14.2",
31+
"@babel/preset-env": "^7.14.1",
32+
"@babel/preset-react": "^7.13.13",
33+
"@babel/preset-typescript": "^7.13.0",
34+
"@remix-run/node": "^1.0.3",
35+
"@remix-run/react": "^1.1.1",
36+
"@remix-run/server-runtime": "^1.0.0",
37+
"@types/jest": "^26.0.23",
38+
"@typescript-eslint/eslint-plugin": "^4.23.0",
39+
"@typescript-eslint/parser": "^4.23.0",
40+
"babel-jest": "^26.6.3",
41+
"eslint": "^7.26.0",
42+
"eslint-config-prettier": "^8.3.0",
43+
"eslint-plugin-jest": "^24.3.6",
44+
"eslint-plugin-jest-dom": "^3.9.0",
45+
"eslint-plugin-prettier": "^3.4.0",
46+
"eslint-plugin-unicorn": "^32.0.1",
47+
"jest": "^26.6.3",
48+
"jest-fetch-mock": "^3.0.3",
49+
"prettier": "^2.3.2",
50+
"react": "^17.0.2",
51+
"ts-node": "^9.1.1",
52+
"typescript": "^4.3.5"
53+
},
54+
"dependencies": {
55+
"remix-auth": "^3.0.0"
56+
}
57+
}

0 commit comments

Comments
 (0)