Skip to content

Commit a7f5499

Browse files
committed
Adds POC Login Form in React
1 parent ac3cbcb commit a7f5499

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

demo/demo/settings.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,14 @@
116116
ACCOUNT_AUTHENTICATION_METHOD = 'username'
117117
ACCOUNT_EMAIL_VERIFICATION = 'optional'
118118

119+
REST_USE_JWT = True
120+
JWT_AUTH_COOKIE = 'auth'
121+
119122
REST_FRAMEWORK = {
120123
'DEFAULT_AUTHENTICATION_CLASSES': (
121124
'rest_framework.authentication.SessionAuthentication',
122125
'rest_framework.authentication.TokenAuthentication',
126+
'dj_rest_auth.utils.JWTCookieAuthentication'
123127
),
124128
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
125129
}
@@ -130,4 +134,5 @@
130134
}
131135

132136

133-
CORS_ORIGIN_ALLOW_ALL = True # For demo purposes only. Use a white list in the real world.
137+
# For demo purposes only. Use a white list in the real world.
138+
CORS_ORIGIN_ALLOW_ALL = True

demo/react-spa/src/App.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.App {
22
text-align: center;
3+
width: 100%;
34
}
45

56
.App-logo {
@@ -22,6 +23,7 @@
2223
justify-content: center;
2324
font-size: calc(10px + 2vmin);
2425
color: white;
26+
width: 100%;
2527
}
2628

2729
.App-link {

demo/react-spa/src/App.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,28 @@ function App() {
1818
body: JSON.stringify({username, password})
1919
}).then(resp => resp.json()).then(data => {
2020
changeResponse(data)
21-
})
21+
}).catch(error => console.log('error ->', error))
2222
}
2323

2424
return (
2525
<div className="App">
2626
<header className="App-header">
27-
<p>
27+
<h1>
2828
Login
29-
</p>
30-
<p>
31-
29+
</h1>
30+
<div className={'help-text'}>
31+
Inspect the network requests in your browser to view headers returned by dj-rest-auth.
32+
</div>
33+
<div>
3234
{resp &&
33-
<span>Response: {JSON.stringify(resp)}</span>
35+
<div className={'response'}>
36+
<code>
37+
{JSON.stringify(resp)}
38+
</code>
39+
</div>
3440
}
35-
</p>
41+
</div>
42+
<div>
3643
<form onSubmit={onSubmit}>
3744
<div>
3845
<input
@@ -50,6 +57,7 @@ function App() {
5057
</div>
5158
<button type={'submit'}>Submit</button>
5259
</form>
60+
</div>
5361
</header>
5462
</div>
5563
);

demo/react-spa/src/index.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,48 @@
11
body {
22
margin: 0;
3+
width: 100%;
34
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
45
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
56
sans-serif;
67
-webkit-font-smoothing: antialiased;
78
-moz-osx-font-smoothing: grayscale;
9+
display: flex;
10+
flex-direction: column;
11+
}
12+
13+
body div {
14+
flex-direction: row;
15+
text-align: center;
16+
display: flex;
17+
justify-content: center;
18+
}
19+
20+
ul {
21+
width: 240px;
22+
font-size: 11px;
823
}
924

1025
code {
1126
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
1227
monospace;
28+
word-break: break-all;
29+
height: 200px;
30+
color: #0f0f0f;
31+
}
32+
33+
.response {
34+
margin: 20px;
35+
background-color: #eee;
36+
width: 80%;
37+
height: 200px;
38+
overflow: scroll;
39+
}
40+
41+
.help-text {
42+
font-size: 11px;
43+
margin: 20px;
44+
}
45+
46+
form > div {
47+
margin: 20px;
1348
}

0 commit comments

Comments
 (0)