bug: fixed router navigating to homepage on page loads

This commit is contained in:
David Kalmakoff 2024-11-05 16:01:26 -06:00 committed by Jannis Mattheis
parent b08b5ae82c
commit 13d59eb04d
2 changed files with 11 additions and 14 deletions

View File

@ -15,7 +15,7 @@ export class CurrentUser {
@observable @observable
public loggedIn = false; public loggedIn = false;
@observable @observable
public authenticating = false; public authenticating = true;
@observable @observable
public user: IUser = {name: 'unknown', admin: false, id: -1}; public user: IUser = {name: 'unknown', admin: false, id: -1};
@observable @observable
@ -80,17 +80,11 @@ export class CurrentUser {
.then((resp: AxiosResponse<IClient>) => { .then((resp: AxiosResponse<IClient>) => {
this.snack(`A client named '${name}' was created for your session.`); this.snack(`A client named '${name}' was created for your session.`);
this.setToken(resp.data.token); this.setToken(resp.data.token);
this.tryAuthenticate() this.tryAuthenticate().catch(() => {
.then(() => { console.log(
this.authenticating = false; 'create client succeeded, but authenticated with given token failed'
this.loggedIn = true; );
}) });
.catch(() => {
this.authenticating = false;
console.log(
'create client succeeded, but authenticated with given token failed'
);
});
}) })
.catch(() => { .catch(() => {
this.authenticating = false; this.authenticating = false;
@ -100,6 +94,7 @@ export class CurrentUser {
public tryAuthenticate = async (): Promise<AxiosResponse<IUser>> => { public tryAuthenticate = async (): Promise<AxiosResponse<IUser>> => {
if (this.token() === '') { if (this.token() === '') {
this.authenticating = false;
return Promise.reject(); return Promise.reject();
} }
@ -111,11 +106,13 @@ export class CurrentUser {
.then((passThrough) => { .then((passThrough) => {
this.user = passThrough.data; this.user = passThrough.data;
this.loggedIn = true; this.loggedIn = true;
this.authenticating = false;
this.connectionErrorMessage = null; this.connectionErrorMessage = null;
this.reconnectTime = 7500; this.reconnectTime = 7500;
return passThrough; return passThrough;
}) })
.catch((error: AxiosError) => { .catch((error: AxiosError) => {
this.authenticating = false;
if (!error || !error.response) { if (!error || !error.response) {
this.connectionError('No network connection or server unavailable.'); this.connectionError('No network connection or server unavailable.');
return Promise.reject(error); return Promise.reject(error);

View File

@ -24,8 +24,8 @@ const $dialog = selector.form('#add-edit-user-dialog');
describe('User', () => { describe('User', () => {
it('does login', async () => await auth.login(page)); it('does login', async () => await auth.login(page));
it('navigates to users', async () => { it('navigates to users through window location', async () => {
await page.click('#navigate-users'); await page.goto(gotify.url + '/#/users');
await waitForExists(page, selector.heading(), 'Users'); await waitForExists(page, selector.heading(), 'Users');
}); });
it('has changed url', async () => { it('has changed url', async () => {