-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathquickstart.txt
114 lines (73 loc) · 2.71 KB
/
quickstart.txt
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
.. _web-quick-start:
=====================
Quick Start - Web SDK
=====================
.. contents:: On this page
:local:
:backlinks: none
:depth: 2
:class: singlecol
Overview
--------
This page shows you how to connect the Realm Web SDK to an Atlas App Services
backend, authenticate a user, and work with data. Before you begin, you'll
need to :ref:`create an App <create-a-realm-app>` for your web app to use.
.. _web-quickstart-install:
Install the Web SDK
-------------------
.. tabs::
.. tab:: npm
:tabid: npm
.. code-block:: shell
npm install realm-web
.. tab:: yarn
:tabid: yarn
.. code-block:: shell
yarn add realm-web
.. tab:: CDN
:tabid: CDN
Add a ``<script>`` tag to the ``<head>`` of your HTML file to load
the Realm Web SDK as a global variable from a content delivery
network.
Use the most recent version:
.. code-block:: html
<script src="https://unpkg.com/realm-web/dist/bundle.iife.js"></script>
Or import a specific version:
.. code-block:: html
<script src="https://unpkg.com/realm-web@1.5.1/dist/bundle.iife.js"></script>
.. _web-quickstart-import-realm:
Import the Web SDK
------------------
Near the top of any JavaScript or TypeScript file that uses Realm, add the
following import statement:
.. literalinclude:: /examples/generated/web/quick-start.test.snippet.import-realm.js
:language: javascript
.. note::
If you loaded the SDK using a ``<script>`` tag then you don't need to import
the SDK to use it. Instead, you can access it using the global ``Realm``
variable.
.. _web-quickstart-init-app:
Initialize the App
------------------
.. include:: /includes/access-app-id.rst
.. literalinclude:: /examples/generated/web/quick-start.test.snippet.initialize-realm-app.js
:language: javascript
.. _web-quickstart-authenticate:
Authenticate a User
-------------------
When :ref:`anonymous authentication <anonymous-authentication>` is enabled,
users can log into your app without providing any identifying information:
.. literalinclude:: /examples/generated/web/quick-start.test.snippet.authenticate-user.js
:language: javascript
App Services provides many additional ways to authenticate, register, and
link users.
.. seealso::
:ref:`Authenticate a User <web-authenticate>`
.. _web-quickstart-function:
Call a Function
---------------
To call a :ref:`function <functions>`, use the ``Realm.User.functions``
interface to :ref:`call your serverless functions <web-call-a-function>` as if
they were regular JavaScript functions defined on the object.
.. literalinclude:: /examples/generated/web/quick-start.test.snippet.call-a-function.js
:language: javascript