-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples/react-parcel-js): update react-auth build to support ts…
… and js
- Loading branch information
Showing
6 changed files
with
115 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
dist/ |
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 @@ | ||
<!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> |
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 @@ | ||
{ | ||
"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" | ||
} | ||
} |
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,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') | ||
) |
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