1import * as Linking from 'expo-linking';
2import * as WebBrowser from 'expo-web-browser';
3import React from 'react';
4
5import FunctionDemo, { FunctionDescription } from '../../components/FunctionDemo';
6
7const FUNCTION_DESCRIPTION: FunctionDescription = {
8  name: 'openAuthSessionAsync',
9  parameters: [
10    {
11      name: 'url',
12      type: 'constant',
13      value: 'url',
14    },
15    { name: 'redirectUrl', type: 'constant', value: Linking.createURL('redirect') },
16    {
17      name: 'options',
18      type: 'object',
19      properties: [{ name: 'createTask', type: 'boolean', initial: true }],
20    },
21  ],
22  additionalParameters: [{ name: 'shouldPrompt', type: 'boolean', initial: false }],
23  actions: (
24    _: string,
25    redirectUrl: string,
26    options: WebBrowser.WebBrowserOpenOptions,
27    shouldPrompt: boolean
28  ) => {
29    const url = `https://fake-auth.netlify.com?state=faker&redirect_uri=${encodeURIComponent(
30      redirectUrl
31    )}&prompt=${shouldPrompt ? 'consent' : 'none'}`;
32    return WebBrowser.openAuthSessionAsync(url, redirectUrl, options);
33  },
34};
35
36export default function OpenAuthSessionAsyncDemo() {
37  return <FunctionDemo namespace="WebBrowser" {...FUNCTION_DESCRIPTION} />;
38}
39