-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #979 from umbraco/feature-split-auth-and-user
Improvement: Split Current User from auth
- Loading branch information
Showing
28 changed files
with
459 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { RuntimeLevelModel, ServerResource } from '@umbraco-cms/backoffice/backend-api'; | ||
import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api'; | ||
import { tryExecute } from '@umbraco-cms/backoffice/resources'; | ||
|
||
export class UmbServerConnection { | ||
#url: string; | ||
#status: RuntimeLevelModel = RuntimeLevelModel.UNKNOWN; | ||
|
||
#isConnected = new UmbBooleanState(false); | ||
isConnected = this.#isConnected.asObservable(); | ||
|
||
constructor(serverUrl: string) { | ||
this.#url = serverUrl; | ||
} | ||
|
||
/** | ||
* Connects to the server. | ||
* @memberof UmbServerConnection | ||
*/ | ||
async connect() { | ||
await this.#setStatus(); | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets the URL of the server. | ||
* @return {*} | ||
* @memberof UmbServerConnection | ||
*/ | ||
getUrl() { | ||
return this.#url; | ||
} | ||
|
||
/** | ||
* Gets the status of the server. | ||
* @return {string} | ||
* @memberof UmbServerConnection | ||
*/ | ||
getStatus() { | ||
if (!this.getIsConnected()) throw new Error('Server is not connected. Remember to await connect()'); | ||
return this.#status; | ||
} | ||
|
||
/** | ||
* Checks if the server is connected. | ||
* @return {boolean} | ||
* @memberof UmbServerConnection | ||
*/ | ||
getIsConnected() { | ||
return this.#isConnected.getValue(); | ||
} | ||
|
||
async #setStatus() { | ||
const { data, error } = await tryExecute(ServerResource.getServerStatus()); | ||
if (error) { | ||
throw error; | ||
} | ||
|
||
this.#isConnected.next(true); | ||
this.#status = data?.serverStatus ?? RuntimeLevelModel.UNKNOWN; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.