-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathindex.js
43 lines (41 loc) · 1.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// :snippet-start: log-in-index-js
import { useEffect } from "react";
import * as Realm from "realm-web";
import Link from "next/link";
import { useApp } from "../components/useApp";
export default function Home() {
const app = useApp();
// note: useEffect runs in the browser but does not run during server-side rendering
useEffect(() => {
// If no logged in user, log in
if (app && !app.currentUser) {
const anonymousUser = Realm.Credentials.anonymous();
app.logIn(anonymousUser);
}
}, [app, app?.currentUser]);
return (
//Your app
// :remove-start:
<div>
<h1>Realm Web & Next.js Examples</h1>
<ul>
<li>
<Link href="/mongodb-data-access">
MongoDB Data Access (Client-side rendering)
</Link>
</li>
<li>
<Link href="/graphql">Atlas GraphQL API (Client-side rendering)</Link>
</li>
<li>
<Link href="/server-side-rendering">Server Side Rendering</Link>
</li>
<li>
<Link href="/static-rendering">Static Rendering</Link>
</li>
</ul>
</div>
// :remove-end:
);
}
// :snippet-end: