Skip to content

Commit e6f8a27

Browse files
authored
Merge pull request #57 from criipto/convert-example-to-ts
Convert example app to TypeScript
2 parents 65d41f1 + e3db783 commit e6f8a27

9 files changed

Lines changed: 53 additions & 9 deletions

File tree

example/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
"private": true,
55
"dependencies": {
66
"@criipto/verify-react": "..",
7+
"@types/react": "../node_modules/@types/react",
8+
"@types/react-dom": "../node_modules/@types/react-dom",
79
"react": "../node_modules/react",
810
"react-dom": "../node_modules/react-dom",
9-
"react-scripts": "5.0.1"
11+
"react-scripts": "5.0.1",
12+
"typescript": "../node_modules/typescript"
1013
},
1114
"homepage": ".",
1215
"scripts": {
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { useCriiptoVerify, AuthMethodSelector } from '@criipto/verify-react';
2+
import { useCriiptoVerify, AuthMethodSelector, OAuth2Error } from '@criipto/verify-react';
33
import Header from './Header';
44
import Login from './Login';
55
import Loading from './Loading';
@@ -12,7 +12,7 @@ function App() {
1212
const { claims, isLoading, logout, error } = useCriiptoVerify();
1313

1414
const handleLogout = () => {
15-
logout('http://localhost:3000');
15+
logout({ redirectUri: 'http://localhost:3000' });
1616
};
1717

1818
return (
@@ -21,7 +21,10 @@ function App() {
2121
{isLoading && <Loading />}
2222
{error ? (
2323
<p>
24-
An error occurred: {error.error} ({error.error_description})
24+
An error occurred:{' '}
25+
{error instanceof OAuth2Error
26+
? `${error.error} (${error.error_description})`
27+
: String(error)}
2528
</p>
2629
) : null}
2730
{claims ? (
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import React from 'react';
2+
import type { useCriiptoVerify } from '@criipto/verify-react';
23
import './App.css';
34

4-
function Dashboard({ user: { name, birthdate, country, cprNumberIdentifier, iat } }) {
5+
type Claims = NonNullable<ReturnType<typeof useCriiptoVerify>['claims']>;
6+
7+
interface DashboardProps {
8+
user: Claims;
9+
}
10+
11+
function Dashboard({
12+
user: { name, birthdate, country, cprNumberIdentifier, iat },
13+
}: DashboardProps) {
514
return (
615
<div className="user-dashboard main">
716
<h2>Welcome to your savings dashboard, {name}</h2>
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import React from 'react';
2+
import type { useCriiptoVerify } from '@criipto/verify-react';
23
import './App.css';
34

4-
function Header({ handleLogout, user }) {
5+
interface HeaderProps {
6+
handleLogout: () => void;
7+
user: ReturnType<typeof useCriiptoVerify>['claims'];
8+
}
9+
10+
function Header({ handleLogout, user }: HeaderProps) {
511
return (
612
<header className="App-header">
713
<p>Example Pension App</p>
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import React from 'react';
22
import './App.css';
33

4-
function Login({ children }) {
4+
interface LoginProps {
5+
children: React.ReactNode;
6+
}
7+
8+
function Login({ children }: LoginProps) {
59
return (
610
<div className="login main">
711
<p>Please login to access your pension savings.</p>
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import './index.css';
44
import App from './App';
55
import { CriiptoVerifyProvider } from '@criipto/verify-react';
66

7-
const root = ReactDOM.createRoot(document.getElementById('root'));
7+
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
88
root.render(
99
<React.StrictMode>
1010
<CriiptoVerifyProvider
1111
domain="samples.criipto.id"
1212
clientID="urn:criipto:samples:criipto:verify-react"
13-
redirectUri="http://localhost:3000"
1413
sessionStore={window.localStorage}
1514
>
1615
<App />

example/tsconfig.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2017",
4+
"lib": ["dom", "dom.iterable", "esnext"],
5+
"allowJs": true,
6+
"skipLibCheck": true,
7+
"esModuleInterop": true,
8+
"allowSyntheticDefaultImports": true,
9+
"strict": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"noFallthroughCasesInSwitch": true,
12+
"module": "esnext",
13+
"moduleResolution": "bundler",
14+
"resolveJsonModule": true,
15+
"isolatedModules": true,
16+
"noEmit": true,
17+
"jsx": "react-jsx"
18+
},
19+
"include": ["src"]
20+
}

0 commit comments

Comments
 (0)