( input: RunOAuthCallbackInput<TAuth, E, R>, )
| 179 | * can still render and close itself. |
| 180 | */ |
| 181 | export const runOAuthCallback = <TAuth, E, R>( |
| 182 | input: RunOAuthCallbackInput<TAuth, E, R>, |
| 183 | ): Effect.Effect<string, never, R> => { |
| 184 | const providerError = providerErrorMessage(input.urlParams); |
| 185 | const callbackState = decodeOAuthCallbackState(input.urlParams.state); |
| 186 | const sessionId = callbackState?.state ?? input.urlParams.state; |
| 187 | const result = |
| 188 | providerError == null |
| 189 | ? input |
| 190 | .complete({ |
| 191 | state: sessionId, |
| 192 | code: input.urlParams.code ?? null, |
| 193 | error: null, |
| 194 | callbackDomain: input.urlParams.domain ?? input.urlParams.site ?? null, |
| 195 | }) |
| 196 | .pipe( |
| 197 | Effect.map( |
| 198 | (auth): OAuthPopupResult<TAuth> => ({ |
| 199 | type: OAUTH_POPUP_MESSAGE_TYPE, |
| 200 | ok: true, |
| 201 | sessionId, |
| 202 | ...auth, |
| 203 | }), |
| 204 | ), |
| 205 | ) |
| 206 | : Effect.succeed<OAuthPopupResult<TAuth>>({ |
| 207 | type: OAUTH_POPUP_MESSAGE_TYPE, |
| 208 | ok: false, |
| 209 | sessionId, |
| 210 | error: providerError.short, |
| 211 | ...(providerError.details ? { errorDetails: providerError.details } : {}), |
| 212 | }); |
| 213 | |
| 214 | return result.pipe( |
| 215 | Effect.catchCause((cause) => { |
| 216 | const { short, details } = input.toErrorMessage(Cause.squash(cause)); |
| 217 | return Effect.succeed<OAuthPopupResult<TAuth>>({ |
| 218 | type: OAUTH_POPUP_MESSAGE_TYPE, |
| 219 | ok: false, |
| 220 | sessionId, |
| 221 | error: short, |
| 222 | ...(details && details !== short ? { errorDetails: details } : {}), |
| 223 | }); |
| 224 | }), |
| 225 | Effect.tap((result) => |
| 226 | Effect.sync(() => completionListener?.(result as OAuthPopupResult<unknown>)), |
| 227 | ), |
| 228 | Effect.map((result) => popupDocument(result, input.channelName)), |
| 229 | ); |
| 230 | }; |
no test coverage detected