Skip to content

Commit a4e756e

Browse files
committed
chore: run pre-commit
1 parent d2a606d commit a4e756e

File tree

11 files changed

+93
-113
lines changed

11 files changed

+93
-113
lines changed

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Long version;
3131
## Example
3232

3333
```tsx
34-
import {AuthContext, AuthProvider, TAuthConfig, TRefreshTokenExpiredEvent} from "react-oauth2-code-pkce"
34+
import { AuthContext, AuthProvider, TAuthConfig, TRefreshTokenExpiredEvent } from "react-oauth2-code-pkce"
3535

3636
const authConfig: TAuthConfig = {
3737
clientId: 'myClientID',
@@ -43,20 +43,20 @@ const authConfig: TAuthConfig = {
4343
}
4444

4545
const UserInfo = (): JSX.Element => {
46-
const {token, tokenData} = useContext<IAuthContext>(AuthContext)
47-
48-
return <>
49-
<h4>Access Token</h4>
50-
<pre>{token}</pre>
51-
<h4>User Information from JWT</h4>
52-
<pre>{JSON.stringify(tokenData, null, 2)}</pre>
53-
</>
46+
const {token, tokenData} = useContext<IAuthContext>(AuthContext)
47+
48+
return <>
49+
<h4>Access Token</h4>
50+
<pre>{token}</pre>
51+
<h4>User Information from JWT</h4>
52+
<pre>{JSON.stringify(tokenData, null, 2)}</pre>
53+
</>
5454
}
5555

5656
ReactDOM.render(<AuthProvider authConfig={authConfig}>
57-
<UserInfo/>
58-
</AuthProvider>
59-
, document.getElementById('root'),
57+
<UserInfo/>
58+
</AuthProvider>
59+
, document.getElementById('root'),
6060
)
6161
```
6262

@@ -131,7 +131,7 @@ type TAuthConfig = {
131131
// Which URL the auth provider should redirect the user to after successful authentication/login
132132
redirectUri: string // Required
133133
// Which scopes to request for the auth token
134-
scope?: string // Default: ''
134+
scope?: string // default: ''
135135
// Optional state value. Will often make more sense to provide the state in a call to the 'logIn()' function
136136
state?: string // default: null
137137
// Which URL to call for logging out of the auth provider
@@ -146,7 +146,7 @@ type TAuthConfig = {
146146
postLogin?: () => void // default: () => null
147147
// Which method to use for login. Can be 'redirect', 'replace', or 'popup'
148148
// Note that most browsers block popups by default. The library will print a warning and fallback to redirect if the popup is blocked
149-
loginMethod: 'redirect' | 'replace' | 'popup' | 'native' // Default: 'redirect'
149+
loginMethod: 'redirect' | 'replace' | 'popup' | 'native' // default: 'redirect'
150150
// Optional callback function for the native login method. If loginMethod is set to 'native', this function,
151151
// which become required, will be called with the URL to open in the native browser(browser in app or somewhere else).
152152
// This is used to open the native login flow on mobile devices.
@@ -159,7 +159,7 @@ type TAuthConfig = {
159159
decodeToken?: boolean // default: true
160160
// By default, the package will automatically redirect the user to the login server if not already logged in.
161161
// If set to false, you need to call the "logIn()" function to log in (e.g. with a "Log in" button)
162-
autoLogin?: boolean // Default: true
162+
autoLogin?: boolean // default: true
163163
// Store login state in 'localStorage' or 'sessionStorage'
164164
// If set to 'session', no login state is persisted by 'react-oauth2-code-pkce` when the browser closes.
165165
// NOTE: Many authentication servers will keep the client logged in by cookies. You should therefore use
@@ -186,7 +186,7 @@ type TAuthConfig = {
186186
// - 'absolute': The refresh token's expiration time is fixed from its initial issuance and does not change, regardless of how many times it is used.
187187
refreshTokenExpiryStrategy?: 'renewable' | 'absolute' // default: renewable
188188
// Whether or not to post 'scope' when refreshing the access token
189-
refreshWithScope?: boolean // Default: true
189+
refreshWithScope?: boolean // default: true
190190
// Controls whether browser credentials (cookies, TLS client certificates, or authentication headers containing a username and password) are sent when requesting tokens.
191191
// Warning: Including browser credentials deviates from the standard protocol and can introduce unforeseen security issues. Only set this to 'include' if you know what
192192
// you are doing and CSRF protection is present. Setting this to 'include' is required when the token endpoint requires client certificate authentication, but likely is
@@ -220,20 +220,20 @@ This can be solved by marking the module with `use client` and importing the com
220220
'use client'
221221
import {useContext} from "react";
222222
import dynamic from 'next/dynamic'
223-
import {TAuthConfig, TRefreshTokenExpiredEvent, AuthContext} from 'react-oauth2-code-pkce'
223+
import {TAuthConfig,TRefreshTokenExpiredEvent, AuthContext} from 'react-oauth2-code-pkce'
224224

225225
const AuthProvider = dynamic(
226-
() => import("react-oauth2-code-pkce")
227-
.then((mod) => mod.AuthProvider),
228-
{ssr: false}
226+
()=> import("react-oauth2-code-pkce")
227+
.then((mod) => mod.AuthProvider),
228+
{ssr: false}
229229
)
230230

231231
const authConfig: TAuthConfig = {...for you to fill inn}
232232

233233
export default function Authenticated() {
234-
(<AuthProvider authConfig={authConfig}>
235-
<LoginInfo/>
236-
</AuthProvider>)
234+
(<AuthProvider authConfig={authConfig}>
235+
<LoginInfo/>
236+
</AuthProvider>)
237237
}
238238
```
239239

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { CapacitorConfig } from '@capacitor/cli';
1+
import type { CapacitorConfig } from '@capacitor/cli'
22

33
const config: CapacitorConfig = {
44
appId: 'com.example.app',
55
appName: 'react-capacitor-app',
6-
webDir: 'dist'
7-
};
6+
webDir: 'dist',
7+
}
88

9-
export default config;
9+
export default config

examples/react-capacitor-app/app/eslint.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import js from '@eslint/js'
2-
import globals from 'globals'
32
import reactHooks from 'eslint-plugin-react-hooks'
43
import reactRefresh from 'eslint-plugin-react-refresh'
5-
import tseslint from 'typescript-eslint'
64
import { globalIgnores } from 'eslint/config'
5+
import globals from 'globals'
6+
import tseslint from 'typescript-eslint'
77

88
export default tseslint.config([
99
globalIgnores(['dist']),

examples/react-capacitor-app/app/src/App.tsx

Lines changed: 43 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { useContext, useEffect } from 'react'
2-
import reactLogo from './assets/react.svg'
32
import viteLogo from '/vite.svg'
3+
import reactLogo from './assets/react.svg'
44
import './App.css'
5-
import { AuthContext } from 'react-oauth2-code-pkce'
6-
import { Capacitor } from '@capacitor/core'
75
import { App as CapacitorApp } from '@capacitor/app'
6+
import { Capacitor } from '@capacitor/core'
7+
import { AuthContext } from 'react-oauth2-code-pkce'
88

99
function App() {
1010
const { tokenData, token, logOut, idToken, error, logIn } = useContext(AuthContext)
@@ -33,21 +33,19 @@ function App() {
3333
return (
3434
<>
3535
<div>
36-
<a href="https://vite.dev" target="_blank">
37-
<img src={viteLogo} className="logo" alt="Vite logo" />
36+
<a href='https://vite.dev' target='_blank' rel='noreferrer'>
37+
<img src={viteLogo} className='logo' alt='Vite logo' />
3838
</a>
39-
<a href="https://react.dev" target="_blank">
40-
<img src={reactLogo} className="logo react" alt="React logo" />
39+
<a href='https://react.dev' target='_blank' rel='noreferrer'>
40+
<img src={reactLogo} className='logo react' alt='React logo' />
4141
</a>
4242
</div>
4343
<h1>Vite + React + OAuth2</h1>
44-
<div className="card">
44+
<div className='card'>
4545
<div style={{ color: '#ff6b6b', marginBottom: '1rem' }}>
4646
An error occurred during authentication: {error}
4747
</div>
48-
<button onClick={() => logOut()}>
49-
Log out
50-
</button>
48+
<button onClick={() => logOut()}>Log out</button>
5149
</div>
5250
</>
5351
)
@@ -56,48 +54,44 @@ function App() {
5654
return (
5755
<>
5856
<div>
59-
<a href="https://vite.dev" target="_blank">
60-
<img src={viteLogo} className="logo" alt="Vite logo" />
57+
<a href='https://vite.dev' target='_blank' rel='noreferrer'>
58+
<img src={viteLogo} className='logo' alt='Vite logo' />
6159
</a>
62-
<a href="https://react.dev" target="_blank">
63-
<img src={reactLogo} className="logo react" alt="React logo" />
60+
<a href='https://react.dev' target='_blank' rel='noreferrer'>
61+
<img src={reactLogo} className='logo react' alt='React logo' />
6462
</a>
6563
</div>
6664

6765
<h1>
6866
Vite + React + OAuth2
6967
{Capacitor.isNativePlatform() && (
70-
<span style={{
71-
fontSize: '0.6em',
72-
color: '#61dafb',
73-
display: 'block',
74-
marginTop: '0.5rem'
75-
}}>
68+
<span
69+
style={{
70+
fontSize: '0.6em',
71+
color: '#61dafb',
72+
display: 'block',
73+
marginTop: '0.5rem',
74+
}}
75+
>
7676
📱 Native App ({Capacitor.getPlatform()})
7777
</span>
7878
)}
7979
</h1>
8080

81-
<div className="card">
81+
<div className='card'>
8282
{token ? (
8383
// Authenticated state
8484
<>
85-
<p style={{ fontSize: '1.2rem', color: '#61dafb' }}>
86-
Welcome, you are connected! 🎉
87-
</p>
85+
<p style={{ fontSize: '1.2rem', color: '#61dafb' }}>Welcome, you are connected! 🎉</p>
8886

89-
<button onClick={() => logOut()}>
90-
Log out
91-
</button>
87+
<button onClick={() => logOut()}>Log out</button>
9288

9389
<p>
9490
Edit <code>src/App.tsx</code> and save to test HMR
9591
</p>
9692

9793
<details style={{ marginTop: '1rem' }}>
98-
<summary style={{ cursor: 'pointer', color: '#888' }}>
99-
Show authentication token
100-
</summary>
94+
<summary style={{ cursor: 'pointer', color: '#888' }}>Show authentication token</summary>
10195
<pre
10296
style={{
10397
maxWidth: '400px',
@@ -109,7 +103,7 @@ function App() {
109103
wordBreak: 'break-all',
110104
whiteSpace: 'pre-wrap',
111105
fontSize: '0.8rem',
112-
overflow: 'auto'
106+
overflow: 'auto',
113107
}}
114108
>
115109
{token}
@@ -119,30 +113,27 @@ function App() {
119113
) : (
120114
// Unauthenticated state
121115
<>
122-
<p style={{ fontSize: '1.1rem', marginBottom: '0.5rem' }}>
123-
Please login to continue
124-
</p>
116+
<p style={{ fontSize: '1.1rem', marginBottom: '0.5rem' }}>Please login to continue</p>
125117

126118
<p style={{ color: '#888', fontSize: '0.9rem' }}>
127119
{Capacitor.isNativePlatform()
128-
? "Tap the button below to authenticate via in-app browser"
129-
: "Connect with your Microsoft account to access the application"
130-
}
120+
? 'Tap the button below to authenticate via in-app browser'
121+
: 'Connect with your Microsoft account to access the application'}
131122
</p>
132123

133-
<button onClick={() => logIn()}>
134-
{Capacitor.isNativePlatform() ? '🔐 Login' : 'Log in'}
135-
</button>
124+
<button onClick={() => logIn()}>{Capacitor.isNativePlatform() ? '🔐 Login' : 'Log in'}</button>
136125

137126
{Capacitor.isNativePlatform() && (
138-
<div style={{
139-
marginTop: '1rem',
140-
padding: '0.5rem',
141-
backgroundColor: '#1a1a1a',
142-
borderRadius: '4px',
143-
fontSize: '0.8rem',
144-
color: '#888'
145-
}}>
127+
<div
128+
style={{
129+
marginTop: '1rem',
130+
padding: '0.5rem',
131+
backgroundColor: '#1a1a1a',
132+
borderRadius: '4px',
133+
fontSize: '0.8rem',
134+
color: '#888',
135+
}}
136+
>
146137
<p>🔧 Debug: Deep link scheme configured</p>
147138
<p>Platform: {Capacitor.getPlatform()}</p>
148139
</div>
@@ -151,11 +142,10 @@ function App() {
151142
)}
152143
</div>
153144

154-
<p className="read-the-docs">
145+
<p className='read-the-docs'>
155146
{Capacitor.isNativePlatform()
156-
? "Enjoy seamless OAuth authentication in your native app!"
157-
: "Click on the Vite and React logos to learn more"
158-
}
147+
? 'Enjoy seamless OAuth authentication in your native app!'
148+
: 'Click on the Vite and React logos to learn more'}
159149
</p>
160150
</>
161151
)

examples/react-capacitor-app/app/src/main.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { Browser } from '@capacitor/browser'
2+
import { Capacitor } from '@capacitor/core'
13
import React from 'react'
2-
import ReactDOM from 'react-dom/client'
4+
import ReactDOM, { createRoot } from 'react-dom/client'
35
import { AuthProvider, type TAuthConfig } from 'react-oauth2-code-pkce'
4-
import { Capacitor } from '@capacitor/core'
5-
import { Browser } from '@capacitor/browser'
66
import App from './App.tsx'
77
import './index.css'
88

@@ -45,8 +45,7 @@ const authConfig: TAuthConfig = {
4545
clientId: '6559ce69-219d-4e82-b6ed-889a861c7c94',
4646
authorizationEndpoint:
4747
'https://login.microsoftonline.com/d422398d-b6a5-454d-a202-7ed4c1bec457/oauth2/v2.0/authorize',
48-
tokenEndpoint:
49-
'https://login.microsoftonline.com/d422398d-b6a5-454d-a202-7ed4c1bec457/oauth2/v2.0/token',
48+
tokenEndpoint: 'https://login.microsoftonline.com/d422398d-b6a5-454d-a202-7ed4c1bec457/oauth2/v2.0/token',
5049

5150
// Use deep link for Capacitor, localhost for web
5251
redirectUri: isCapacitor()
@@ -85,10 +84,13 @@ const authConfig: TAuthConfig = {
8584
* Root component that wraps the App with AuthProvider
8685
* This ensures authentication context is available throughout the app
8786
*/
88-
ReactDOM.createRoot(document.getElementById('root')!).render(
87+
const container = document.getElementById('root')
88+
if (!container) throw new Error('No container found')
89+
const root = createRoot(container)
90+
root.render(
8991
<React.StrictMode>
9092
<AuthProvider authConfig={authConfig}>
9193
<App />
9294
</AuthProvider>
93-
</React.StrictMode>,
95+
</React.StrictMode>
9496
)

examples/react-capacitor-app/app/tsconfig.app.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
"lib": ["ES2022", "DOM", "DOM.Iterable"],
77
"module": "ESNext",
88
"skipLibCheck": true,
9-
10-
/* Bundler mode */
119
"moduleResolution": "bundler",
1210
"allowImportingTsExtensions": true,
1311
"verbatimModuleSyntax": true,
1412
"moduleDetection": "force",
1513
"noEmit": true,
1614
"jsx": "react-jsx",
17-
18-
/* Linting */
1915
"strict": true,
2016
"noUnusedLocals": true,
2117
"noUnusedParameters": true,

examples/react-capacitor-app/app/tsconfig.node.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
"lib": ["ES2023"],
66
"module": "ESNext",
77
"skipLibCheck": true,
8-
9-
/* Bundler mode */
108
"moduleResolution": "bundler",
119
"allowImportingTsExtensions": true,
1210
"verbatimModuleSyntax": true,
1311
"moduleDetection": "force",
1412
"noEmit": true,
15-
16-
/* Linting */
1713
"strict": true,
1814
"noUnusedLocals": true,
1915
"noUnusedParameters": true,

0 commit comments

Comments
 (0)