-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moralis auth firebase extension + demo.
* moralis auth firebase extension + demo. poc.
- Loading branch information
Showing
39 changed files
with
1,217 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@moralisweb3/client-firebase-auth': patch | ||
--- | ||
|
||
Add client package for Firebase authentication. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"projects": {}, | ||
"targets": {}, | ||
"etags": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules/ | ||
lib/ | ||
.firebase/ | ||
*.env | ||
*-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Authenticate with Moralis Extension for Firebase Demo | ||
|
||
This project contains a simple authentication demo for the Firebase by a Web3 wallet. It uses the Authenticate with Moralis Auth extension for the Firebase. | ||
|
||
Required Google Cloud services: | ||
|
||
- [Firebase Hosting](https://firebase.google.com/docs/hosting) | ||
- [Firebase Authentication](https://firebase.google.com/docs/auth) | ||
- [Firebase Cloud Functions](https://firebase.google.com/docs/functions) (only in the Blaze plan, check the [pricing](https://firebase.google.com/pricing)). | ||
- [Secret Manager](https://cloud.google.com/secret-manager/) (check the [pricing](https://cloud.google.com/secret-manager/pricing)) | ||
|
||
## 🚀 How to Start | ||
|
||
1. Clone this repo. | ||
2. [Install Firebase CLI](https://firebase.google.com/docs/cli) globally: `npm install -g firebase-tools` | ||
3. Login to your account: `firebase login` | ||
4. Get list of your projects: `firebase projects:list`. If this list is empty you should add a new project. You can do it by the Firebase Console. | ||
5. Set your project ID: `firebase use <PROJECT_ID>` | ||
6. Generate a certificate for the [Service Account](https://firebase.google.com/support/guides/service-accounts). You will need it in the next step. | ||
7. Convert the certificate to extension variables by [this online converter](https://moralisweb3.github.io/firebase-extensions/service-account-converter/). You will use these variables in the next step. | ||
8. Install the Authenticate with Moralis Web3 extension: `firebase ext:install moralis/moralis-auth`. | ||
9. Copy `hosting/.env.example` to `hosting/.env` and set all variables. | ||
10. Build the functions project: | ||
* `cd functions` | ||
* `npm install` | ||
* `npm run build` | ||
11. Build the hosting project: | ||
* `cd hosting` | ||
* `npm install` | ||
* `npm run build` | ||
|
||
### 🔌 Run Locally | ||
|
||
1. [Install Java](https://www.oracle.com/java/technologies/javase/jdk18-archive-downloads.html) on your computer. Functions Emulator requires Java. | ||
2. Run emulators: `firebase emulators:start` | ||
3. Open `http://localhost:5555/` in your browser. | ||
|
||
### 🔥 Deploy to Production | ||
|
||
1. Deploy: `firebase deploy` | ||
2. If you have any problem with the CORS on the production, probably you should allow unauthenticated HTTP function invocation. To allow unauthenticated invocation you must specify this at or after deployment. [Here](https://cloud.google.com/functions/docs/securing/managing-access-iam#allowing_unauthenticated_http_function_invocation) you can read more about it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"functions": { | ||
"ignore": ["node_modules"], | ||
"source": "functions", | ||
"predeploy": [ | ||
"yarn --cwd \"$RESOURCE_DIR\" install", | ||
"yarn --cwd \"$RESOURCE_DIR\" run lint", | ||
"yarn --cwd \"$RESOURCE_DIR\" run build" | ||
] | ||
}, | ||
"hosting": { | ||
"ignore": ["node_modules"], | ||
"public": "hosting/build", | ||
"predeploy": [ | ||
"yarn --cwd \"$RESOURCE_DIR\" install", | ||
"yarn --cwd \"$RESOURCE_DIR\" run lint", | ||
"yarn --cwd \"$RESOURCE_DIR\" run build" | ||
] | ||
}, | ||
"emulators": { | ||
"hosting": { | ||
"port": 5555 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
extends: ['@moralisweb3'], | ||
ignorePatterns: ['**/lib/**/*'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Compiled JavaScript files | ||
lib/**/*.js | ||
lib/**/*.js.map | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# Node.js dependency directory | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "demo-firebase-auth-ext-functions", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"lint": "eslint --ext .js,.ts .", | ||
"build": "tsc", | ||
"build:watch": "tsc --watch" | ||
}, | ||
"engines": { | ||
"node": "16" | ||
}, | ||
"main": "lib/index.js", | ||
"dependencies": { | ||
"firebase-functions": "^3.18.0", | ||
"firebase-admin": "^10.3.0" | ||
}, | ||
"devDependencies": { | ||
"@moralisweb3/eslint-config": "^1.0.0", | ||
"typescript": "^4.5.4", | ||
"@typescript-eslint/eslint-plugin": "^5.36.2", | ||
"@typescript-eslint/parser": "^5.36.2", | ||
"eslint-plugin-etc": "^2.0.2", | ||
"firebase-functions-test": "^0.2.0" | ||
}, | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as functions from 'firebase-functions'; | ||
|
||
// ~/getSecretData | ||
|
||
export const getSecretData = functions.https.onCall(async (data, context) => { | ||
if (!context.auth?.uid) { | ||
throw new functions.https.HttpsError('permission-denied', 'You are not authorized to call this function'); | ||
} | ||
|
||
const secretValue = 'I am a secret'; | ||
return { secretValue }; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"include": ["./.eslintrc.js"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"noImplicitReturns": true, | ||
"noUnusedLocals": true, | ||
"outDir": "lib", | ||
"sourceMap": true, | ||
"strict": true, | ||
"target": "es2017", | ||
"esModuleInterop": true, | ||
"resolveJsonModule": true, | ||
"skipLibCheck": true | ||
}, | ||
"compileOnSave": true, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# To get the configuration of your Firebase app: | ||
# open the Firebase Console > Project Settings > General > Your Apps and click Add app > Web app | ||
# or | ||
# execute `firebase apps:sdkconfig` command in the project directory | ||
|
||
REACT_APP_FIREBASE_API_KEY=replace_me | ||
REACT_APP_FIREBASE_AUTH_DOMAIN=replace_me | ||
REACT_APP_FIREBASE_PROJECT_ID=replace_me | ||
REACT_APP_FIREBASE_STORAGE_BUCKET=replace_me | ||
REACT_APP_FIREBASE_MESSAGING_SENDER_ID=replace_me | ||
REACT_APP_FIREBASE_APP_ID=replace_me |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
extends: ['@moralisweb3'], | ||
ignorePatterns: ['**/lib/**/*'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "demo-firebase-auth-ext-hosting", | ||
"version": "1.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@ethersproject/providers": "^5.7.1", | ||
"@moralisweb3/client-firebase-auth": "^2.5.2", | ||
"@testing-library/jest-dom": "^5.16.5", | ||
"@testing-library/react": "^13.4.0", | ||
"@testing-library/user-event": "^13.5.0", | ||
"@types/jest": "^27.5.2", | ||
"@types/node": "^16.11.58", | ||
"@types/react": "^18.0.19", | ||
"@types/react-dom": "^18.0.6", | ||
"bs58": "^5.0.0", | ||
"firebase": "^9.9.4", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-scripts": "5.0.1", | ||
"typescript": "^4.8.3", | ||
"web-vitals": "^2.1.4" | ||
}, | ||
"scripts": { | ||
"lint": "eslint --ext .js,.ts ./src", | ||
"build": "react-scripts build", | ||
"eject": "react-scripts eject" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"react-app", | ||
"react-app/jest" | ||
] | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Moralis Auth Demo</title> | ||
|
||
<style> | ||
body { | ||
font: 14px/1.4em Arial, Verdana, Tahoma, Serif; | ||
text-align: center; | ||
} | ||
button { | ||
margin: 0 5px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
|
||
<div id="root"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# https://www.robotstxt.org/robotstxt.html | ||
User-agent: * | ||
Disallow: |
Oops, something went wrong.