Skip to content

Commit c78bd6f

Browse files
author
Benjamin RICHARD
committed
fix #96 login jwt form now works as expected
1 parent bff3370 commit c78bd6f

File tree

9 files changed

+630
-303
lines changed

9 files changed

+630
-303
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ For [Angular](https://angular.io/) (v5), i decided to do quite different way:
131131
* install the project with `npm run init-project` (or init-project:win for windows system) which will launch :
132132
1. copy the env file (or set them on your system) : `cp .env.dist .env`
133133
2. php dependancies installation: `composer install`
134-
3. nodejs tooling installation (and angular deps): `npm install && cd assets/js/devxpress-angular && npm install`
134+
3. nodejs tooling installation (and angular deps): `npm install && cd assets/js/form-devxpress-angular && npm install`
135135
4. assets generation: `npm run dev`
136136
5. db init: `php bin/console doctrine:database:create` & `doctrine:schema:create` & `doctrine:fixtures:load`
137137
* it creates the physical database from the `config/packages/doctrine.yaml` file
@@ -142,15 +142,16 @@ For [Angular](https://angular.io/) (v5), i decided to do quite different way:
142142
2. Run `npm run jwt-init` and use the passphrase you setup for JWT_PASSPHRASE
143143
* Run your application with php built-in server:
144144
1. Change to the project directory
145-
2. Execute the `npm run dev-server-hot` (or dev-server-hot:win for windows system) command to start the asset server that will build your assets and your manifest.json and serve the assets with hot module replacment when you do a modification on a vuejs file
146-
3. Execute the `npm run sf-dev` (or sf-dev:win for windows system) command;
147-
4. Browse to the http://localhost:80/ URL.
145+
2. Execute the `npm run build` that will build assets and watch for angular app change
146+
3. Execute the `npm run dev-server-hot` (or dev-server-hot:win for windows system) command to start the asset server that will build your assets for vue and react and your manifest.json and serve the assets with hot module replacement when you do a modification on a vuejs file
147+
4. Execute the `npm run sf-dev` (or sf-dev:win for windows system) command;
148+
5. Browse to the http://localhost:80/ URL.
148149

149150
* Run composer require symfony/web-server-bundle for a better web server.
150151
* Quit the server with CTRL-C.
151152
* And launch `php bin/console server:start 127.0.0.1:80`
152153

153-
5. Run frontend tests with `npm run test`
154+
6. Run frontend tests with `npm run test`
154155

155156
Don't forget to prefer an nginx/apache server to be able to use full features of api-platform.
156157

assets/js/api-platform-admin-react/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const fetchHeaders = (options) => {
1111
return
1212
}
1313

14-
options.headers.set('Authorization', `Bearer ${token}`);
14+
options.headers.set('Authorization', `${token}`);
1515
};
1616
const fetchWithAuth = (url, options = {}) => {
1717
if (!options.headers) options.headers = new Headers({ Accept: 'application/ld+json' });

assets/js/lib/login.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ axios.interceptors.request.eject(logoutStdInterceptors)
1818

1919
// @todo move it to RxJs implementation with subscribe + only call the uri on last call of the method during 300ms
2020
export default function isLoggedIn(loaderToActivate, uri = loginInfos.uriIsLoggedIn.json) {
21+
debugger
2122
return new Promise((resolve, reject) => {
2223
if (loaderToActivate && loaderToActivate.isLoading) {
2324
loaderToActivate.isLoading = true

assets/js/login/components/Secured.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default {
2323
QSpinnerCircles,
2424
Notify
2525
},
26+
props: ['loggedInUri'],
2627
data() {
2728
return {
2829
user: {},
@@ -61,7 +62,7 @@ export default {
6162
})
6263
this.$router.push('Login')
6364
})
64-
isLoggedIn()
65+
isLoggedIn(undefined, this.loggedInUri)
6566
},
6667
}
6768
</script>

assets/js/login/router/index.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,23 @@ if (!redirect) {
5454

5555
let loggedInUri = loginInfos.uriIsLoggedIn.json
5656
let loginUri = decodeURIComponent(
57-
location.search
58-
.substr(1)
59-
.split('&')
60-
.filter(item => item.split('=')[0] === 'mode')
61-
.map(item => {
62-
if (!item) {
57+
// looks for jwt or json string in uri, it will determine which uri to login with (this is only for this demo app, you should not have to do this)
58+
location.pathname
59+
.split('/')
60+
.filter(item => ['json', 'jwt'].includes(item))
61+
.map(mode => {
62+
if (!mode) {
6363
return
6464
}
6565

66-
const mode = item.split('=')[1]
67-
if (['json', 'jwt'].includes(mode)) {
68-
switch (mode) {
69-
case 'jwt':
70-
loggedInUri = loginInfos.uriIsLoggedIn.jwt
66+
switch (mode) {
67+
case 'jwt':
68+
loggedInUri = loginInfos.uriIsLoggedIn.jwt
7169

72-
return loginInfos.uriLogin.jwt
73-
case 'json':
74-
default:
75-
return loginInfos.uriLogin.json
76-
}
70+
return loginInfos.uriLogin.jwt
71+
case 'json':
72+
default:
73+
return loginInfos.uriLogin.json
7774
}
7875
})
7976
.join('')
@@ -100,7 +97,10 @@ export default new Router({
10097
path: '/secured',
10198
name: 'Secured',
10299
component: Secured,
103-
props: true,
100+
props: {
101+
default: true,
102+
loggedInUri: loggedInUri,
103+
},
104104
beforeEnter: vueRouterIsLoggedIn,
105105
},
106106
],

0 commit comments

Comments
 (0)