Skip to content

Commit dea19e7

Browse files
committed
feat(examples/react-parcel-js): update react-auth build to support ts and js
1 parent 397998b commit dea19e7

File tree

6 files changed

+115
-13
lines changed

6 files changed

+115
-13
lines changed

examples/react-parcel-js/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
dist/

examples/react-parcel-js/index.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>Tensei, TypeScript, React, Parcel Starter!</title>
9+
</head>
10+
11+
<body>
12+
<div id="app"></div>
13+
<script src="src/App.js" type="text/javascript"></script>
14+
</body>
15+
16+
</html>

examples/react-parcel-js/package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "@examples/react-parcel",
3+
"version": "0.8.17",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"private": true,
7+
"devDependencies": {
8+
"@types/react": "^17.0.13",
9+
"@types/react-dom": "^17.0.8",
10+
"parcel-bundler": "^1.12.5",
11+
"react": "^17.0.2",
12+
"react-dom": "^17.0.2",
13+
"typescript": "^4.3.5"
14+
},
15+
"scripts": {
16+
"example:dev": "parcel index.html"
17+
},
18+
"gitHead": "92a29de45627693db340d3b4a503f52eddc2fb27",
19+
"dependencies": {
20+
"react-router-dom": "^5.2.0"
21+
}
22+
}

examples/react-parcel-js/src/App.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import * as React from 'react'
2+
import * as ReactDOM from 'react-dom'
3+
import { BrowserRouter, Route } from 'react-router-dom'
4+
5+
import { TenseiAuthProvider, useAuth, useTensei } from '@tensei/react-auth'
6+
7+
console.log(TenseiAuthProvider)
8+
9+
const Auth = () => {
10+
const tensei = useTensei()
11+
const { isLoading, user } = useAuth()
12+
13+
const login = () => {
14+
tensei.auth().login({
15+
object: {
16+
17+
password: 'password',
18+
accepted_terms_and_conditions: true
19+
}
20+
})
21+
}
22+
23+
const logout = () => {
24+
tensei.auth().logout()
25+
}
26+
27+
if (isLoading) {
28+
return null
29+
}
30+
31+
if (user) {
32+
return (
33+
<>
34+
<button onClick={logout}>
35+
Logout
36+
</button>
37+
</>
38+
)
39+
}
40+
41+
return (
42+
<>
43+
<button onClick={login}>
44+
Login
45+
</button>
46+
<br />
47+
<br />
48+
<br />
49+
<a href={tensei.auth().socialRedirectUrl('google')}>
50+
Login with google
51+
</a>
52+
</>
53+
)
54+
}
55+
56+
const App = () => {
57+
return (
58+
<BrowserRouter>
59+
<TenseiAuthProvider options={{
60+
refreshTokens: true
61+
}}>
62+
<Route component={Auth} path='/' />
63+
</TenseiAuthProvider>
64+
</BrowserRouter>
65+
)
66+
}
67+
68+
ReactDOM.render(
69+
<App />,
70+
document.getElementById('app')
71+
)

examples/react-parcel/src/App.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react'
22
import * as ReactDOM from 'react-dom'
33
import { BrowserRouter, Route } from 'react-router-dom'
44

5-
import { AuthContextProvider, useAuth, useTensei } from '@tensei/react-auth'
5+
import { TenseiAuthProvider, useAuth, useTensei } from '@tensei/react-auth'
66

77
const Auth: React.FunctionComponent = () => {
88
const tensei = useTensei()
@@ -54,11 +54,11 @@ const Auth: React.FunctionComponent = () => {
5454
const App: React.FunctionComponent = () => {
5555
return (
5656
<BrowserRouter>
57-
<AuthContextProvider options={{
57+
<TenseiAuthProvider options={{
5858
refreshTokens: true
5959
}}>
6060
<Route component={Auth} path='/' />
61-
</AuthContextProvider>
61+
</TenseiAuthProvider>
6262
</BrowserRouter>
6363
)
6464
}

packages/react-auth/tsconfig.build.json

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
{
22
"compilerOptions": {
33
"declaration": true,
4-
"declarationMap": true,
5-
"esModuleInterop": true,
6-
"forceConsistentCasingInFileNames": true,
7-
"importHelpers": true,
84
"module": "commonjs",
95
"moduleResolution": "node",
10-
"noFallthroughCasesInSwitch": true,
11-
"noImplicitAny": true,
12-
"noImplicitReturns": true,
13-
"noImplicitThis": true,
14-
"sourceMap": true,
156
"target": "es6",
16-
"resolveJsonModule": true,
177
"jsx": "react",
188
"outDir": "./dist",
9+
"esModuleInterop": true,
1910
"skipLibCheck": true,
2011
"types": ["jest", "node", "@testing-library/jest-dom"]
2112
},

0 commit comments

Comments
 (0)