Skip to content

Commit

Permalink
feat(examples/react-parcel-js): update react-auth build to support ts…
Browse files Browse the repository at this point in the history
… and js
  • Loading branch information
bahdcoder committed Jul 4, 2021
1 parent 397998b commit dea19e7
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 13 deletions.
2 changes: 2 additions & 0 deletions examples/react-parcel-js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
16 changes: 16 additions & 0 deletions examples/react-parcel-js/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Tensei, TypeScript, React, Parcel Starter!</title>
</head>

<body>
<div id="app"></div>
<script src="src/App.js" type="text/javascript"></script>
</body>

</html>
22 changes: 22 additions & 0 deletions examples/react-parcel-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@examples/react-parcel",
"version": "0.8.17",
"main": "index.js",
"license": "MIT",
"private": true,
"devDependencies": {
"@types/react": "^17.0.13",
"@types/react-dom": "^17.0.8",
"parcel-bundler": "^1.12.5",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"typescript": "^4.3.5"
},
"scripts": {
"example:dev": "parcel index.html"
},
"gitHead": "92a29de45627693db340d3b4a503f52eddc2fb27",
"dependencies": {
"react-router-dom": "^5.2.0"
}
}
71 changes: 71 additions & 0 deletions examples/react-parcel-js/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import { BrowserRouter, Route } from 'react-router-dom'

import { TenseiAuthProvider, useAuth, useTensei } from '@tensei/react-auth'

console.log(TenseiAuthProvider)

const Auth = () => {
const tensei = useTensei()
const { isLoading, user } = useAuth()

const login = () => {
tensei.auth().login({
object: {
email: 'parcel@tenseijs.com',
password: 'password',
accepted_terms_and_conditions: true
}
})
}

const logout = () => {
tensei.auth().logout()
}

if (isLoading) {
return null
}

if (user) {
return (
<>
<button onClick={logout}>
Logout
</button>
</>
)
}

return (
<>
<button onClick={login}>
Login
</button>
<br />
<br />
<br />
<a href={tensei.auth().socialRedirectUrl('google')}>
Login with google
</a>
</>
)
}

const App = () => {
return (
<BrowserRouter>
<TenseiAuthProvider options={{
refreshTokens: true
}}>
<Route component={Auth} path='/' />
</TenseiAuthProvider>
</BrowserRouter>
)
}

ReactDOM.render(
<App />,
document.getElementById('app')
)
6 changes: 3 additions & 3 deletions examples/react-parcel/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react'
import * as ReactDOM from 'react-dom'
import { BrowserRouter, Route } from 'react-router-dom'

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

const Auth: React.FunctionComponent = () => {
const tensei = useTensei()
Expand Down Expand Up @@ -54,11 +54,11 @@ const Auth: React.FunctionComponent = () => {
const App: React.FunctionComponent = () => {
return (
<BrowserRouter>
<AuthContextProvider options={{
<TenseiAuthProvider options={{
refreshTokens: true
}}>
<Route component={Auth} path='/' />
</AuthContextProvider>
</TenseiAuthProvider>
</BrowserRouter>
)
}
Expand Down
11 changes: 1 addition & 10 deletions packages/react-auth/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"module": "commonjs",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"sourceMap": true,
"target": "es6",
"resolveJsonModule": true,
"jsx": "react",
"outDir": "./dist",
"esModuleInterop": true,
"skipLibCheck": true,
"types": ["jest", "node", "@testing-library/jest-dom"]
},
Expand Down

0 comments on commit dea19e7

Please sign in to comment.