PHP Classes

File: assets/js/components/lib/ValidadorToken.js

Recommend this page to a friend!
  Classes of Rodrigo Faustino   Web App Multi-Perfil   assets/js/components/lib/ValidadorToken.js   Download  
File: assets/js/components/lib/ValidadorToken.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Web App Multi-Perfil
App that uses CRUD to manage multiple users
Author: By
Last change:
Date: 8 months ago
Size: 2,116 bytes
 

Contents

Class file image Download
import BuscaApi from './BuscaApiG.js'; import Navbar from '../Navbar.js'; export default class ValidadorToken { constructor(navigateCallback,userLanguage) { this.navigate = navigateCallback; this.buscaApi = new BuscaApi(sessionStorage.getItem('token')); this.token = sessionStorage.getItem('token'); this.navbar = null; this.userLanguage = userLanguage; } async init() { if (!this.token) { this.initializeNavbarPublico(); } else { await this.validaToken(); setInterval(() => this.validaToken(), 10000); } } async validaToken() { if (this.navbar) { this.navbar.updatePermitidas(this.telasPermitidas); } try { const data = await this.buscaApi.fetchApi('token', 'GET'); if(data.status) { this.telasPermitidas = data.telas; this.initializeNavbar(); } else { sessionStorage.removeItem('token'); location.reload(); } } catch (error) { console.error("Erro ao validar token:", error); this.redirecioneLogin(); } } initializeNavbar() { if (!this.navbar) { this.navbar = new Navbar(this.navigate, this.telasPermitidas); const navbarElement = this.navbar.renderRestrito(); document.body.insertBefore(navbarElement, document.getElementById('app')); this.navbar.init(); } else { this.navbar.updatePermitidas(this.telasPermitidas); } } initializeNavbarPublico() { if (!this.navbar) { this.navbar = new Navbar(this.navigate, this.telasPermitidas); const navbarElement = this.navbar.render(); document.body.insertBefore(navbarElement, document.getElementById('app')); this.navbar.init(); } else { this.navbar.updatePermitidas(this.telasPermitidas); } } redirecioneLogin() { this.navigate('login'); } }