Created
September 26, 2022 17:58
-
-
Save Mikepicker/eb1bb867cee6bbe9747f7f20c8c826a9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <html> | |
| <head> | |
| ... | |
| </head> | |
| <body> | |
| ... | |
| <script> | |
| document.addEventListener('alpine:init', () => { | |
| Alpine.data('lists', () => ({ | |
| // VARIABLES | |
| async init () { | |
| // initialize pocketbase | |
| this.client = new PocketBase('http://127.0.0.1:8090'); | |
| // capture invalid token | |
| this.client.afterSend = function (response, data) { | |
| if (response.status === 401) { | |
| this.showLogin = true | |
| } | |
| return data | |
| } | |
| // if user is not logged in, show login / signup page | |
| if (!window.localStorage.getItem('pocketbase_auth')) { | |
| this.showLogin = true | |
| return | |
| } | |
| // resume session | |
| const auth = JSON.parse(window.localStorage.getItem('pocketbase_auth')) | |
| this.client.authStore.save(auth.token, auth.model) | |
| // fetch todo lists | |
| this.getLists() | |
| // suscribe to live update events | |
| this.subscribeToLists() | |
| }, | |
| })) | |
| }) | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment