Skip to content

Commit

Permalink
chore: better Prettier config for easier reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
theoludwig committed Oct 23, 2023
1 parent 2d84d11 commit 5f2742b
Show file tree
Hide file tree
Showing 18 changed files with 1,254 additions and 1,254 deletions.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/BUG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: '🐛 Bug Report'
about: 'Report an unexpected problem or unintended behavior.'
title: '[Bug]'
labels: 'bug'
name: "🐛 Bug Report"
about: "Report an unexpected problem or unintended behavior."
title: "[Bug]"
labels: "bug"
---

<!--
Expand Down
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/DOCUMENTATION.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: '📜 Documentation'
about: 'Correct spelling errors, improvements or additions to documentation files (README, CONTRIBUTING...).'
title: '[Documentation]'
labels: 'documentation'
name: "📜 Documentation"
about: "Correct spelling errors, improvements or additions to documentation files (README, CONTRIBUTING...)."
title: "[Documentation]"
labels: "documentation"
---

<!-- Please make sure your issue has not already been fixed. -->
Expand Down
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/FEATURE_REQUEST.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: '✨ Feature Request'
about: 'Suggest a new feature idea.'
title: '[Feature]'
labels: 'feature request'
name: "✨ Feature Request"
about: "Suggest a new feature idea."
title: "[Feature]"
labels: "feature request"
---

<!-- Please make sure your issue has not already been fixed. -->
Expand Down
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/IMPROVEMENT.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: '🔧 Improvement'
about: 'Improve structure/format/performance/refactor/tests of the code.'
title: '[Improvement]'
labels: 'improvement'
name: "🔧 Improvement"
about: "Improve structure/format/performance/refactor/tests of the code."
title: "[Improvement]"
labels: "improvement"
---

<!-- Please make sure your issue has not already been fixed. -->
Expand Down
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/QUESTION.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: '🙋 Question'
about: 'Further information is requested.'
title: '[Question]'
labels: 'question'
name: "🙋 Question"
about: "Further information is requested."
title: "[Question]"
labels: "question"
---

### Question
24 changes: 12 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Build'
name: "Build"

on:
push:
Expand All @@ -8,20 +8,20 @@ on:

jobs:
build:
runs-on: 'ubuntu-latest'
runs-on: "ubuntu-latest"
steps:
- uses: 'actions/checkout@v4.0.0'
- uses: "actions/checkout@v4.0.0"

- name: 'Setup Node.js'
uses: 'actions/setup-node@v3.8.1'
- name: "Setup Node.js"
uses: "actions/setup-node@v3.8.1"
with:
node-version: '20.x'
cache: 'npm'
node-version: "20.x"
cache: "npm"

- name: 'Install dependencies'
run: 'npm clean-install'
- name: "Install dependencies"
run: "npm clean-install"

- name: 'Build'
run: 'npm run build'
- name: "Build"
run: "npm run build"

- run: 'npm run build:typescript'
- run: "npm run build:typescript"
26 changes: 13 additions & 13 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Lint'
name: "Lint"

on:
push:
Expand All @@ -8,21 +8,21 @@ on:

jobs:
lint:
runs-on: 'ubuntu-latest'
runs-on: "ubuntu-latest"
steps:
- uses: 'actions/checkout@v4.0.0'
- uses: "actions/checkout@v4.0.0"

- name: 'Setup Node.js'
uses: 'actions/setup-node@v3.8.1'
- name: "Setup Node.js"
uses: "actions/setup-node@v3.8.1"
with:
node-version: '20.x'
cache: 'npm'
node-version: "20.x"
cache: "npm"

- name: 'Install dependencies'
run: 'npm clean-install'
- name: "Install dependencies"
run: "npm clean-install"

- run: 'npm run lint:commit -- --to "${{ github.sha }}"'
- run: 'npm run lint:editorconfig'
- run: 'npm run lint:markdown'
- run: 'npm run lint:eslint'
- run: 'npm run lint:prettier'
- run: "npm run lint:editorconfig"
- run: "npm run lint:markdown"
- run: "npm run lint:eslint"
- run: "npm run lint:prettier"
40 changes: 20 additions & 20 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
name: 'Release'
name: "Release"

on:
push:
branches: [master]

jobs:
release:
runs-on: 'ubuntu-latest'
runs-on: "ubuntu-latest"
permissions:
contents: 'write'
issues: 'write'
pull-requests: 'write'
id-token: 'write'
contents: "write"
issues: "write"
pull-requests: "write"
id-token: "write"
steps:
- uses: 'actions/checkout@v4.0.0'
- uses: "actions/checkout@v4.0.0"

- name: 'Setup Node.js'
uses: 'actions/setup-node@v3.8.1'
- name: "Setup Node.js"
uses: "actions/setup-node@v3.8.1"
with:
node-version: '20.x'
cache: 'npm'
node-version: "20.x"
cache: "npm"

- name: 'Install dependencies'
run: 'npm clean-install'
- name: "Install dependencies"
run: "npm clean-install"

- name: 'Build Package'
run: 'npm run build'
- name: "Build Package"
run: "npm run build"

- run: 'npm run build:typescript'
- run: "npm run build:typescript"

- name: 'Verify the integrity of provenance attestations and registry signatures for installed dependencies'
run: 'npm audit signatures'
- name: "Verify the integrity of provenance attestations and registry signatures for installed dependencies"
run: "npm audit signatures"

- name: 'Release'
run: 'npm run release'
- name: "Release"
run: "npm run release"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
26 changes: 13 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Test'
name: "Test"

on:
push:
Expand All @@ -8,21 +8,21 @@ on:

jobs:
test:
runs-on: 'ubuntu-latest'
runs-on: "ubuntu-latest"
steps:
- uses: 'actions/checkout@v4.0.0'
- uses: "actions/checkout@v4.0.0"

- name: 'Setup Node.js'
uses: 'actions/setup-node@v3.8.1'
- name: "Setup Node.js"
uses: "actions/setup-node@v3.8.1"
with:
node-version: '20.x'
cache: 'npm'
node-version: "20.x"
cache: "npm"

- name: 'Install dependencies'
run: 'npm clean-install'
- name: "Install dependencies"
run: "npm clean-install"

- name: 'Build'
run: 'npm run build'
- name: "Build"
run: "npm run build"

- name: 'Test'
run: 'npm run test'
- name: "Test"
run: "npm run test"
5 changes: 1 addition & 4 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"singleQuote": true,
"jsxSingleQuote": true,
"semi": false,
"trailingComma": "none"
"semi": false
}
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@ npm install --save @thream/socketio-jwt
### Server side

```ts
import { Server } from 'socket.io'
import { authorize } from '@thream/socketio-jwt'
import { Server } from "socket.io"
import { authorize } from "@thream/socketio-jwt"

const io = new Server(9000)
io.use(
authorize({
secret: 'your secret or public key'
})
secret: "your secret or public key",
}),
)

io.on('connection', async (socket) => {
io.on("connection", async (socket) => {
// jwt payload of the connected client
console.log(socket.decodedToken)
const clients = await io.sockets.allSockets()
if (clients != null) {
for (const clientId of clients) {
const client = io.sockets.sockets.get(clientId)
client?.emit('messages', { message: 'Success!' })
client?.emit("messages", { message: "Success!" })
// we can access the jwt payload of each connected client
console.log(client?.decodedToken)
}
Expand All @@ -70,12 +70,12 @@ io.on('connection', async (socket) => {
### Server side with `jwks-rsa` (example)

```ts
import jwksClient from 'jwks-rsa'
import { Server } from 'socket.io'
import { authorize } from '@thream/socketio-jwt'
import jwksClient from "jwks-rsa"
import { Server } from "socket.io"
import { authorize } from "@thream/socketio-jwt"

const client = jwksClient({
jwksUri: 'https://sandrino.auth0.com/.well-known/jwks.json'
jwksUri: "https://sandrino.auth0.com/.well-known/jwks.json",
})

const io = new Server(9000)
Expand All @@ -84,11 +84,11 @@ io.use(
secret: async (decodedToken) => {
const key = await client.getSigningKeyAsync(decodedToken.header.kid)
return key.getPublicKey()
}
})
},
}),
)

io.on('connection', async (socket) => {
io.on("connection", async (socket) => {
// jwt payload of the connected client
console.log(socket.decodedToken)
// You can do the same things of the previous example there...
Expand All @@ -98,21 +98,21 @@ io.on('connection', async (socket) => {
### Server side with `onAuthentication` (example)

```ts
import { Server } from 'socket.io'
import { authorize } from '@thream/socketio-jwt'
import { Server } from "socket.io"
import { authorize } from "@thream/socketio-jwt"

const io = new Server(9000)
io.use(
authorize({
secret: 'your secret or public key',
secret: "your secret or public key",
onAuthentication: async (decodedToken) => {
// return the object that you want to add to the user property
// or throw an error if the token is unauthorized
}
})
},
}),
)

io.on('connection', async (socket) => {
io.on("connection", async (socket) => {
// jwt payload of the connected client
console.log(socket.decodedToken)
// You can do the same things of the previous example there...
Expand All @@ -130,23 +130,23 @@ io.on('connection', async (socket) => {
### Client side

```ts
import { io } from 'socket.io-client'
import { isUnauthorizedError } from '@thream/socketio-jwt/build/UnauthorizedError.js'
import { io } from "socket.io-client"
import { isUnauthorizedError } from "@thream/socketio-jwt/build/UnauthorizedError.js"

// Require Bearer Token
const socket = io('http://localhost:9000', {
auth: { token: `Bearer ${yourJWT}` }
const socket = io("http://localhost:9000", {
auth: { token: `Bearer ${yourJWT}` },
})

// Handling token expiration
socket.on('connect_error', (error) => {
socket.on("connect_error", (error) => {
if (isUnauthorizedError(error)) {
console.log('User token has expired')
console.log("User token has expired")
}
})

// Listening to events
socket.on('messages', (data) => {
socket.on("messages", (data) => {
console.log(data)
})
```
Expand Down
Loading

0 comments on commit 5f2742b

Please sign in to comment.