Skip to content

Commit 19729bb

Browse files
committed
Use development tokens for example-nextjs.
1 parent 880ef16 commit 19729bb

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
# Copy to .env.local, and complete these variables.
2+
# Leave blank to test local-only.
13
NEXT_PUBLIC_POWERSYNC_URL=
4+
NEXT_PUBLIC_POWERSYNC_TOKEN=

demos/example-nextjs/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ This example is built using [Next.js](https://nextjs.org/) and the [PowerSync JS
55
To see it in action:
66

77
1. Make sure to run `pnpm build:packages` in the root directory of this Git repo.
8-
2. `pnpm start`
9-
3. Open the localhost URL in the browser displayed in the terminal output.
8+
2. Copy `.env.local.template` to `.env.local`, and complete the environment variables. You can generate a temporary development token on the PowerSync dashboard, or leave blank to test with local-only data.
9+
3. `pnpm start`
10+
4. Open the localhost URL in the browser displayed in the terminal output.

demos/example-nextjs/src/library/powersync/BackendConnector.ts

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
import { AbstractPowerSyncDatabase, BaseObserver, PowerSyncBackendConnector } from '@journeyapps/powersync-sdk-web';
22

3-
export type BackendConfig = {
4-
powersyncUrl: string;
5-
};
6-
7-
export type BackendConnectorListener = {
8-
initialized: () => void;
9-
};
10-
11-
export class BackendConnector extends BaseObserver<BackendConnectorListener> implements PowerSyncBackendConnector {
12-
private _config: BackendConfig;
3+
export class BackendConnector implements PowerSyncBackendConnector {
4+
private powersyncUrl: string | undefined;
5+
private powersyncToken: string | undefined;
136

147
constructor() {
15-
super();
16-
this._config = {
17-
powersyncUrl: process.env.NEXT_PUBLIC_POWERSYNC_URL!
18-
};
8+
this.powersyncUrl = process.env.NEXT_PUBLIC_POWERSYNC_URL;
9+
// This token is for development only.
10+
// For production applications, integrate with an auth provider or custom auth.
11+
this.powersyncToken = process.env.NEXT_PUBLIC_POWERSYNC_TOKEN;
1912
}
2013

2114
async fetchCredentials() {
15+
// TODO: Use an authentication service or custom implementation here.
16+
17+
if (this.powersyncToken == null || this.powersyncUrl == null) {
18+
return null;
19+
}
20+
2221
return {
23-
endpoint: this._config.powersyncUrl,
24-
token: '' // TODO: Implement
22+
endpoint: this.powersyncUrl,
23+
token: this.powersyncToken
2524
};
2625
}
2726

@@ -38,13 +37,11 @@ export class BackendConnector extends BaseObserver<BackendConnectorListener> imp
3837
await transaction.complete();
3938
} catch (error: any) {
4039
if (shouldDiscardDataOnError(error)) {
41-
/**
42-
* Instead of blocking the queue with these errors, discard the (rest of the) transaction.
43-
*
44-
* Note that these errors typically indicate a bug in the application.
45-
* If protecting against data loss is important, save the failing records
46-
* elsewhere instead of discarding, and/or notify the user.
47-
*/
40+
// Instead of blocking the queue with these errors, discard the (rest of the) transaction.
41+
//
42+
// Note that these errors typically indicate a bug in the application.
43+
// If protecting against data loss is important, save the failing records
44+
// elsewhere instead of discarding, and/or notify the user.
4845
console.error(`Data upload error - discarding`, error);
4946
await transaction.complete();
5047
} else {

0 commit comments

Comments
 (0)