Skip to content

Commit eab555d

Browse files
authored
Clarify Google offline refresh docs (#574)
* Clarify Google offline refresh docs * Clarify Google web refresh docs
1 parent 602b256 commit eab555d

5 files changed

Lines changed: 18 additions & 3 deletions

File tree

apps/docs/src/content/docs/docs/plugins/social-login/getting-started.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ const active = await SocialLogin.isRefreshTokenAvailable({ refreshToken: 'a-toke
112112

113113
`google.mode: 'offline'` returns `serverAuthCode` from login. In this mode logout, isLoggedIn, getAuthorizationCode, and refresh are not available.
114114

115+
Use `serverAuthCode` only as input to your backend token exchange. If you need to call `SocialLogin.refresh()` in the app, use `google.mode: 'online'` instead.
116+
115117
### Apple
116118

117119
Set `useProperTokenExchange: true` for strict token handling and `useBroadcastChannel: true` for Android simplified setup.

apps/docs/src/content/docs/docs/plugins/social-login/google/android.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ You may create multiple Android client IDs. This is required if you have multipl
169169
console.log(JSON.stringify(res))
170170
```
171171

172+
:::caution
173+
If you initialize Google with `mode: 'offline'`, `SocialLogin.login()` returns `serverAuthCode` for your backend exchange flow. Do not call `SocialLogin.refresh({ provider: 'google' })` in the app in that mode. Exchange `serverAuthCode` on your backend, store the Google refresh token there, and refresh on the backend.
174+
:::
175+
172176
5. Configure the emulator for testing
173177

174178
1. Go into `Device manager` and click the plus button

apps/docs/src/content/docs/docs/plugins/social-login/google/general.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ There are multiple ways to use Google Login with Capacitor. Here is a table that
113113
**Offline mode REQUIRES a backend server.** When using offline mode, the frontend receives minimal information (primarily just a server auth code). Without a backend to exchange this code for tokens and user information, offline mode provides no useful data to your frontend application.
114114
:::
115115

116+
:::caution
117+
`SocialLogin.refresh({ provider: 'google' })` does **not** work with `google.mode: 'offline'`. In offline mode the plugin only gives you `serverAuthCode`, and your backend must exchange that code for access and refresh tokens, then refresh those tokens on the backend.
118+
:::
119+
116120
If you still do not know which one you should choose, please consider the following scenarios:
117121

118122
1. You want the user to login, immediately after you are going to issue him a custom JWT. Your app will NOT call Google APIs
@@ -233,3 +237,5 @@ async function fullLogin() {
233237
}
234238
}
235239
```
240+
241+
Notice what is missing here: there is no `SocialLogin.refresh()` call in the app. That is intentional. In Google offline mode, refresh happens after your backend exchanges `serverAuthCode` and stores the refresh token securely.

apps/docs/src/content/docs/docs/plugins/social-login/google/ios.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ In this part, you will learn how to setup Google login in iOS.
185185
:::
186186

187187
:::caution
188-
**About offline mode:** When using `mode: 'offline'`, the login response will not contain user data directly. Instead, you'll receive a server auth code that must be exchanged for user information via your backend server. See the [general setup guide](/docs/plugins/social-login/google/general/#using-offline-access-with-your-own-backend) for implementation details.
188+
**About offline mode:** When using `mode: 'offline'`, the login response will not contain user data directly. Instead, you'll receive a server auth code that must be exchanged for user information via your backend server. `SocialLogin.refresh({ provider: 'google' })` is not available in this mode; refresh must happen on your backend after exchanging `serverAuthCode`. See the [general setup guide](/docs/plugins/social-login/google/general/#using-offline-access-with-your-own-backend) for implementation details.
189189
:::
190190

191191
3. Implement the login function. Create a button and run the following code on click
@@ -210,6 +210,7 @@ In this part, you will learn how to setup Google login in iOS.
210210
})
211211
// res contains serverAuthCode, not user data
212212
// Send serverAuthCode to your backend to get user information
213+
// Do not call SocialLogin.refresh() in offline mode
213214
console.log('Server auth code:', res.result.serverAuthCode)
214215
```
215216

@@ -246,4 +247,3 @@ await SocialLogin.login({
246247

247248

248249

249-

apps/docs/src/content/docs/docs/plugins/social-login/google/web.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ In order to use it, you have to do the following:
115115
```
116116
:::
117117

118+
:::caution
119+
On Web, `SocialLogin.refresh({ provider: 'google' })` is not implemented, even when using `google.mode: 'online'`. If you need a fresh Google token on Web, call `SocialLogin.login({ provider: 'google', ... })` again.
120+
:::
121+
118122
3. Create a login button that calls `SocialLogin.login` when clicked
119123

120124
```typescript
@@ -126,4 +130,3 @@ In order to use it, you have to do the following:
126130
console.log(JSON.stringify(res));
127131
```
128132
</Steps>
129-

0 commit comments

Comments
 (0)