https://github.com/alexander-lindner/ng-pocketbase-core
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (9.2%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: alexander-lindner
- License: mpl-2.0
- Language: TypeScript
- Default Branch: main
- Size: 1.07 MB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 3
Metadata Files
README.md
ng-pocketbase
An ready to use angular library for Pocketbase. It provides a set of services for authentication and realtime data handling.
Installation
yarn add @ng-pocketbase/core or npm install @ng-pocketbase/core
API
See GitHub Pages.
Usage
Initialization
In your app.module.ts import the PocketBaseModule and provide the configuration.
```typescript
@NgModule(
{
imports: [
NgPocketbaseCoreModule.forRoot(
new PocketBaseConfig(
environment.backendUrl,
environment.frontendUiUrl,
environment.frontendUiUrl + "/auth/redirect" // the return url for oauth2 logins
)
),
]
},
)
export class AppModule {}
with the environment variables
typescript
export const environment = {
production: false,
frontendUiUrl: 'http://localhost:4200',
backendUrl: 'http://127.0.0.1:8090'
}
```
Service
For every table, create a service that extends BasicCrud
export type Detail = BasicType & { //... }
@Injectable({providedIn: "root"})
export class DetailsService extends BasicCrud
protected createItem(record: Record): Detail {
return {
id: record.id,
feed: record.feed,
weight: parseInt(record.weight),
name: record.name,
};
}
}
``
Additionally, you need a factory methodcreateItem` that creates an instance of your type from a Record.
Now you can use it like so
```typescript
export class DetailsComponent implements OnInit {
private details: Array
constructor(private DetailsService: DetailsService) {}
public ngOnInit(): void {
this.DetailsService.getItems().subscribe((value: Array<Detail>) => {
this.details = value;
});
this.DetailsService.create({...}).subscribe((value: Detail) => { console.log(value.id); // fdsafdsadadfs });
this.DetailsService.getById("fdsafdsadadfs").subscribe((value: Detail) => { });
this.DetailsService.update("fdsafdsadadfs", {name: "test"}).subscribe((value: Detail) => { });
this.DetailsService.delete("fdsafdsadadfs").subscribe((success: boolean) => { });
}
} ```
Authentication
To interact with the authentication service, you need to use the AuthService<U extends User> service that is provided by this package.
The provided user type U reflects the made changes to the user table.
So if you don't change the user table, you can use the provided User type, however, we recommend to create your own (empty) user type that extends the User type.
That way, you can easily add additional fields to the user table later on.
```typescript
export type CustomUser = User & {
}
``
Now you can use theAuthService
```typescript export class CustomAuthComponent implements OnInit { @ViewChild("loginForm") loginForm: NgForm = {} as NgForm; username: string = ""; public isSending: boolean = false; private errorMessage: string = "";
constructor(private auth: AuthService
public ngOnInit(): void { this.username = this.auth.snapshot.userData.username; }
loginWithEmail() {
this.isSending = true;
this.errorMessage = "";
this.auth
.login(this.loginForm.value["email"], this.loginForm.value["password"])
.subscribe(
{
next: () => {
this.isSending = false;
this.router.navigate(["/"]);
},
error: (err: ClientResponseError) => {
this.isSending = false;
this.errorMessage = (err.message) ? err.message : "Unknown error";
},
},
);
}
public logout(): void {
this.auth.logout();
this.router.navigate(["/"]);
}
}
Furthermore, there is the `*isLoggedIn` directive that can be used to only use html elements when logged in or not logged in.
angular2html
```
Interceptors
typescript
providers: [
{ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptorService, multi: true },
//...
]
Example Application
This repository contains an example application that uses the library. It authenticates the user and then displays a list of users.
To run the example application, you need to start the pocketbase server and then run yarn run start.
bash
cd projects/server && go run server.go serve . &
yarn && yarn run start --project app
This will create a user demo (demo@domain.tld) with password demo and a user admin (admin@domain.tld) with password admin.
Owner
- Name: Alexander Lindner
- Login: alexander-lindner
- Kind: user
- Location: Mainz, Germany
- Company: TU Darmstadt
- Website: https://alindner.org
- Repositories: 6
- Profile: https://github.com/alexander-lindner
Hello there!
GitHub Events
Total
Last Year
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 0
- Total pull requests: 12
- Average time to close issues: N/A
- Average time to close pull requests: about 2 hours
- Total issue authors: 0
- Total pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.42
- Merged pull requests: 10
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
- alexander-lindner (10)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- npm 23 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 12
- Total maintainers: 1
npmjs.org: @ng-pocketbase/core
A implementation of the pocketbase api for Angular
- Homepage: https://github.com/alexander-lindner/ng-pocketbase-core/tree/main/projects/ng-pocketbase-core
- License: MPL-2.0
-
Latest release: 0.1.0
published about 3 years ago