DEV Community

Zheng Jiawen
Zheng Jiawen

Posted on

How sync works in tatsu

this is a (internal) documentation of how syncing to cloud providers work in my todo app. Tatsu provides the option to sync to cadav servers via basic auth or Oauth.

provider method
DAViCal basic auth
Baikal basic auth
Apple calendar basic auth
Next cloud basic auth
Google calendar Oauth

Basic auth

basic auth is pretty simple, you basically need 3 things; a server url, username, and password to access the external caldav server's endpoints.
The implementation of such a sync is as follows:

  1. user inputs the server url, username, and password in a form.

  2. tatsu's /calDav/account api is called with the three inputs, this api attempts to connect to the caldav server, and if succesful, stores the three values into tatsu's caldav accounts table.

    note: Each user can only have one caldav account.

  3. tatsu's /calDav/sync api is then called, which connects to the caldav server using the credentials from tatsu's caldav account table, and performs syncing operation on calendar events.

Oauth

Oauth implementation is more complex, but it is way more user friendly. currently only google calendars can be synced this way.

  1. when user clicks on the sync Google calendar button, authJs's signIn function is called with callback_url = tatsu.com/todo/sync?calendarSync=true

    note: callback_url is authjs's way of remembering where to redirect user after oauth.

  2. this signIn function obtains a refresh_token from google servers, then determines if this is a syncing operation by looking at the callback_url. It then stores this refresh_token into the caldav accounts table if the google caldav server can be acessed.

  3. The google consent page then redirects user to tatsu's sync page tatsu.com/todo/sync?calendarSync=true

  4. tatsu's sync page detects the search parameter and calls the /calDav/sync api which does the same thing as the basic auth scenario.

Top comments (0)