Skip to content

Commit

Permalink
doc: web3 auth
Browse files Browse the repository at this point in the history
  • Loading branch information
RSamaium committed Jan 28, 2024
1 parent 4f95fa5 commit f61a24c
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ const migrationMenu = [{
]
}]

const web3Menu = [{
text: 'Web3',
collapsed: false,
items: [
{ text: "Authentification with wallet", link: "/web3/auth" }
]
}]

const guideMenu = [{
text: 'Quick Start',
Expand Down Expand Up @@ -203,6 +210,7 @@ const guideMenu = [{
{ text: "Create Unit Tests", link: "/guide/unit-test" },
]
},
...web3Menu,
...migrationMenu
]

Expand Down Expand Up @@ -276,6 +284,7 @@ module.exports = {
'/advanced/': guideMenu,
'/plugins/': pluginMenu,
'/migration/': guideMenu,
'/web3/': guideMenu,
},
plugins: ['@vuepress/active-header-links'],
head: [
Expand Down
79 changes: 79 additions & 0 deletions docs/web3/auth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Authentification Integrating Web3 into RPGJS

::: warning
The module is not complete. Further developments are in progress
:::

## Overview

By following this guide, you'll be able to connect to a digital wallet like MetaMask and implement Web3 capabilities both on the client and server sides.

### Prerequisites
- Basic knowledge of RPGJS
- Familiarity with Web3 concepts
- MetaMask or similar digital wallet installed

## Frontend Integration

### Customization
You are free to customize the frontend as per your needs. However, an example is provided here for guidance.

### Example:

https://github.com/RSamaium/RPG-JS/tree/v4/packages/sample3

## Server-Side Integration

### Installation

Install the `@rpgjs/web3` plugin:

```bash
npx rpgjs add @rpgjs/web3
```

Ensure that the `@rpgjs/web3` module is the first in the list:

Example:
```toml
modules = [
'@rpgjs/web3',
'./main',
'@rpgjs/default-gui',
]
```

### Setting up Configuration

Add the following configurations:

```toml
[auth]
jwtSecret = 'mysecret'

[express.cors]
origin = '$ENV:VITE_GAME_URL'
credentials = true

[express.socketIo.cors]
origin = '$ENV:VITE_GAME_URL'
credentials = true

[socketIoClient]
withCredentials = true
```

## Usage

### Endpoints
The integration introduces two endpoints:

- `SERVER_URL + '/nonce'`
- `SERVER_URL + '/verify'`

These endpoints help in creating an HTTP-only cookie containing a JWT (JSON Web Token).

### API Utilization
This integration extends the `RpgPlayer` type with Web3 functionalities:

- `player.web3.walletAddress`: Allows access to the player's wallet address.

0 comments on commit f61a24c

Please sign in to comment.