Browse Source

Fix token delay error during login

tags/v0.1.0
Immanuel Onyeka 3 years ago
parent
commit
cead0f26b0
4 changed files with 23 additions and 7 deletions
  1. +7
    -7
      resources/js/main.js
  2. +5
    -0
      resources/js/panel/panel.vue
  3. +5
    -0
      resources/js/panel/sidebar.vue
  4. +6
    -0
      resources/scss/main.scss

+ 7
- 7
resources/js/main.js View File

@@ -20,17 +20,17 @@ function getCookie(name) {
return (value != null) ? unescape(value[1]) : null return (value != null) ? unescape(value[1]) : null
} }


function getToken(app) {
fetch("/sanctum/csrf-cookie", {
function getToken() {
return fetch("/sanctum/csrf-cookie", {
method: 'GET' method: 'GET'
}).then( () => { }).then( () => {
token = getCookie('XSRF-TOKEN') token = getCookie('XSRF-TOKEN')
return token
}) })
app.token = token
} }


function login(event) { function login(event) {
fetch("/login", {
getToken().then(fetch("/login", {
method: 'POST', method: 'POST',
headers: {'Content-Type': 'application/json', headers: {'Content-Type': 'application/json',
'Accept': 'application/json', 'Accept': 'application/json',
@@ -45,9 +45,9 @@ function login(event) {
document.querySelector("#login_form .error").innerText = document.querySelector("#login_form .error").innerText =
"Invalid credentials." "Invalid credentials."
} }
})
}))
event.preventDefault() event.preventDefault()
event.stopPropogation()
// event.stopPropogation()
} }


function getUser(app) { function getUser(app) {
@@ -111,7 +111,7 @@ if (window.location.pathname == '/') {
document.querySelector('#login_form button').addEventListener('click', login) document.querySelector('#login_form button').addEventListener('click', login)
const app = createApp(RegisterArea).mount('#app') const app = createApp(RegisterArea).mount('#app')
// app.token = token // app.token = token
if (!token) {getToken(app)}
if (!token) {app.token = getToken()}


//Triggers for registration menu //Triggers for registration menu
for (let i = 0; i < registerToggles.length; i++) { for (let i = 0; i < registerToggles.length; i++) {


+ 5
- 0
resources/js/panel/panel.vue View File

@@ -59,8 +59,13 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
<img class="nav-btn" src="../../images/arrow-left-circle-fill.svg" alt="">
<img class="nav-btn" src="../../images/arrow-right-circle-fill.svg" alt="">
</section> </section>
</div> </div>
<div d="main" v-else-if="active === '#exit'">
<div class="actions"><a class="new-order" href="#orders/new">New</a></div>
</div>
</transition> </transition>
</template> </template>




+ 5
- 0
resources/js/panel/sidebar.vue View File

@@ -18,6 +18,11 @@
<path d="M3.5 11.5a3.5 3.5 0 1 1 3.163-5H14L15.5 8 14 9.5l-1-1-1 1-1-1-1 1-1-1-1 1H6.663a3.5 3.5 0 0 1-3.163 2zM2.5 9a1 1 0 1 0 0-2 1 1 0 0 0 0 2z"/> <path d="M3.5 11.5a3.5 3.5 0 1 1 3.163-5H14L15.5 8 14 9.5l-1-1-1 1-1-1-1 1-1-1-1 1H6.663a3.5 3.5 0 0 1-3.163 2zM2.5 9a1 1 0 1 0 0-2 1 1 0 0 0 0 2z"/>
</svg> </svg>
</a> </a>
<a :class="{selected: active == '#exit'}" href="/panel#exit">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-door-open-fill" viewBox="0 0 16 16">
<path d="M1.5 15a.5.5 0 0 0 0 1h13a.5.5 0 0 0 0-1H13V2.5A1.5 1.5 0 0 0 11.5 1H11V.5a.5.5 0 0 0-.57-.495l-7 1A.5.5 0 0 0 3 1.5V15H1.5zM11 2h.5a.5.5 0 0 1 .5.5V15h-1V2zm-2.5 8c-.276 0-.5-.448-.5-1s.224-1 .5-1 .5.448.5 1-.224 1-.5 1z"/>
</svg>
</a>
</nav> </nav>
</template> </template>




+ 6
- 0
resources/scss/main.scss View File

@@ -821,6 +821,7 @@ main.panel {
color: grey; color: grey;
height: 0; height: 0;
overflow: hidden; overflow: hidden;
transition: all 0.2s;
} }


.selected .pending-content { .selected .pending-content {
@@ -843,6 +844,11 @@ main.panel {
margin-bottom: 3px; margin-bottom: 3px;
margin-left: 2px; margin-left: 2px;
position: absolute; position: absolute;
transition: all 0.2s;
}

.selected img {
transform: rotate(180deg);
} }
} }




Loading…
Cancel
Save