{"app":{"id":10,"summary":"Supabase authentication","versions":[25,26],"created_by":"josé governo425","created_at":"2023-03-16T20:57:34.917Z","votes":0,"approved":false,"apps":["Supabase","Authentication"],"app_type":"openapp","external_embed_url":null,"value":{"css":{"app":{"grid":{"class":"","style":""},"viewer":{"class":"","style":""},"component":{"class":"","style":""}},"mapcomponent":{"map":{"class":"","style":""}},"pdfcomponent":{"container":{"class":"","style":""}},"formcomponent":{"button":{"class":"","style":""},"container":{"class":"","style":""}},"htmlcomponent":{"container":{"class":"","style":""}},"iconcomponent":{"icon":{"class":"","style":""},"container":{"class":"","style":""}},"tabscomponent":{"tabRow":{"class":"","style":""},"allTabs":{"class":"","style":""},"container":{"class":"","style":""},"selectedTab":{"class":"","style":""}},"textcomponent":{"text":{"class":"","style":""}},"imagecomponent":{"image":{"class":"","style":""}},"rangecomponent":{"bar":{"style":""},"limits":{"class":"","style":""},"values":{"class":"","style":""},"handles":{"style":""}},"tablecomponent":{"container":{"class":"","style":""},"tableBody":{"class":"","style":""},"tableFooter":{"class":"","style":""},"tableHeader":{"class":"","style":""}},"aggridcomponent":{},"buttoncomponent":{"button":{"class":"","style":""}},"drawercomponent":{},"plotlycomponent":{},"selectcomponent":{"input":{"style":""}},"slidercomponent":{"bar":{"style":""},"value":{"class":"","style":""},"handle":{"style":""},"limits":{"class":"","style":""}},"displaycomponent":{"header":{"class":"","style":""},"container":{"class":"","style":""}},"barchartcomponent":{"container":{"class":"","style":""}},"checkboxcomponent":{"text":{"class":"","style":""}},"currencycomponent":{"input":{"class":"","style":""}},"piechartcomponent":{"container":{"class":"","style":""}},"vegalitecomponent":{},"containercomponent":{"container":{"class":"","style":""}},"dateinputcomponent":{"input":{"class":"","style":""}},"fileinputcomponent":{"container":{"class":"","style":""}},"textinputcomponent":{"input":{"class":"","style":""}},"emailinputcomponent":{"input":{"class":"","style":""}},"formbuttoncomponent":{"popup":{"class":"","style":""},"button":{"class":"","style":""}},"timeseriescomponent":{"container":{"class":"","style":""}},"multiselectcomponent":{"input":{"style":""}},"numberinputcomponent":{"input":{"class":"","style":""}},"scatterchartcomponent":{"container":{"class":"","style":""}},"passwordinputcomponent":{"input":{"class":"","style":""}},"resourceselectcomponent":{"input":{"style":""}},"verticaldividercomponent":{"divider":{"class":"","style":""},"container":{"class":"","style":""}},"horizontaldividercomponent":{"divider":{"class":"","style":""},"container":{"class":"","style":""}},"verticalsplitpanescomponent":{"container":{"class":"","style":""}},"horizontalsplitpanescomponent":{"container":{"class":"","style":""}}},"grid":[{"3":{"h":8,"w":2,"x":0,"y":0,"max":{"h":100,"w":3},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"12":{"h":11,"w":12,"x":0,"y":0,"id":"a","max":{"h":100,"w":12},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"id":"a","data":{"id":"a","card":false,"tabs":["Auth","Authenticated"],"type":"tabscomponent","softWrap":true,"customCss":{"tabRow":{"class":"","style":""},"allTabs":{"class":"","style":""},"container":{"class":"","style":""},"selectedTab":{"class":"","style":""}},"configuration":{"tabsKind":{"type":"static","value":"invisibleOnView","fieldType":"select","onlyStatic":true,"optionValuesKey":"tabsKindOptions"}},"numberOfSubgrids":2}}],"subgrids":{"a-0":[{"3":{"h":8,"w":2,"x":0,"y":0,"max":{"h":100,"w":3},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"12":{"h":8,"w":6,"x":3,"y":0,"id":"l","max":{"h":100,"w":12},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"id":"l","data":{"id":"l","type":"containercomponent","softWrap":true,"customCss":{"container":{"class":"","style":""}},"configuration":{},"numberOfSubgrids":1}}],"a-1":[{"3":{"h":8,"w":2,"x":0,"y":0,"max":{"h":100,"w":3},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"12":{"h":9,"w":10,"x":1,"y":0,"id":"k","max":{"h":100,"w":12},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"id":"k","data":{"id":"k","type":"containercomponent","softWrap":true,"customCss":{"container":{"class":"","style":""}},"configuration":{},"numberOfSubgrids":1}}],"k-0":[{"3":{"h":8,"w":2,"x":0,"y":0,"max":{"h":100,"w":3},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"12":{"h":8,"w":9,"x":0,"y":0,"id":"i","max":{"h":100,"w":12},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"id":"i","data":{"id":"i","card":false,"type":"displaycomponent","customCss":{"header":{"class":"","style":""},"container":{"class":"","style":""}},"configuration":{},"componentInput":{"type":"connected","value":{"foo":42},"fieldType":"object","connection":{"path":"result","componentId":"j"}}}},{"3":{"h":1,"w":1,"x":0,"y":8,"max":{"h":100,"w":3},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"12":{"h":1,"w":2,"x":9,"y":0,"id":"j","max":{"h":100,"w":12},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"id":"j","data":{"id":"j","card":false,"type":"buttoncomponent","softWrap":true,"customCss":{"button":{"class":"","style":""}},"configuration":{"goto":{"type":"static","value":"","tooltip":"Go to an url on success if not empty","fieldType":"text"},"size":{"type":"static","value":"xs","fieldType":"select","onlyStatic":true,"optionValuesKey":"buttonSizeOptions"},"color":{"type":"static","value":"blue","fieldType":"select","onlyStatic":true,"optionValuesKey":"buttonColorOptions"},"label":{"type":"static","value":"Query","fieldType":"text"},"disabled":{"expr":"false","type":"eval","fieldType":"boolean"},"afterIcon":{"type":"static","fieldType":"icon-select","onlyStatic":true},"beforeIcon":{"type":"static","fieldType":"icon-select","onlyStatic":true},"gotoNewTab":{"type":"static","value":true,"tooltip":"Go to an url on a new tab","fieldType":"boolean"},"fillContainer":{"type":"static","value":false,"fieldType":"boolean","onlyStatic":true},"triggerOnAppLoad":{"type":"static","value":false,"fieldType":"boolean","onlyStatic":true}},"componentInput":{"type":"runnable","fields":{"auth":{"type":"static","value":"$res:f/asset_allocation/supa_asset_allocation","format":"resource-supabase","fieldType":"object"},"access_token":{"type":"connected","value":null,"fieldType":"string","connection":{"path":"access_token","componentId":"state"}},"refresh_token":{"type":"connected","value":null,"fieldType":"string","connection":{"path":"refresh_token","componentId":"state"}}},"runnable":{"name":"query","type":"runnableByName","inlineScript":{"path":"f/asset_allocation/auth/query","schema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["auth","access_token","refresh_token"],"properties":{"auth":{"type":"object","format":"resource-supabase","default":null,"description":""},"access_token":{"type":"string","default":null,"description":""},"refresh_token":{"type":"string","default":null,"description":""}}},"content":"// import * as wmill from \"https://deno.land/x/windmill@v1.77.0/mod.ts\"\n\nimport { Resource } from \"https://deno.land/x/windmill@v1.77.0/mod.ts\";\nimport { createClient } from \"https://esm.sh/@supabase/supabase-js@2\";\n\nexport async function main(\n  auth: Resource<\"supabase\">,\n  access_token: string,\n  refresh_token: string,\n) {\n  const supabase = createClient(auth.url, auth.key, {\n    global: { headers: { Authorization: `bearer ${access_token}` } },\n  });\n  const { data, error } = await supabase.from(\"profiles\").select();\n  return { data, error };\n}\n","language":"deno"}},"fieldType":"any"},"verticalAlignment":"center","horizontalAlignment":"center"}}],"l-0":[{"3":{"h":1,"w":1,"x":1,"y":3,"max":{"h":100,"w":3},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"12":{"h":1,"w":12,"x":0,"y":0,"id":"r","max":{"h":100,"w":12},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"id":"r","data":{"id":"r","type":"textcomponent","softWrap":true,"customCss":{"text":{"class":"text-red-500","style":""}},"configuration":{"style":{"type":"static","value":"Label","fieldType":"select","onlyStatic":true,"optionValuesKey":"textStyleOptions"},"tooltip":{"type":"static","value":"","tooltip":"Tooltip text if not empty","fieldType":"text","onlyStatic":true},"copyButton":{"type":"static","value":false,"fieldType":"boolean","onlyStatic":true}},"componentInput":{"eval":"${state.message || \" \"}","type":"template","value":"Hello ${ctx.username}","fieldType":"template"},"verticalAlignment":"top","horizontalAlignment":"left"}},{"3":{"h":1,"w":1,"x":0,"y":0,"max":{"h":100,"w":3},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"12":{"h":1,"w":12,"x":0,"y":1,"id":"m","max":{"h":100,"w":12},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"id":"m","data":{"id":"m","type":"textcomponent","softWrap":true,"customCss":{"text":{"class":"","style":""}},"configuration":{"style":{"type":"static","value":"Label","fieldType":"select","onlyStatic":true,"optionValuesKey":"textStyleOptions"},"tooltip":{"type":"static","value":"","tooltip":"Tooltip text if not empty","fieldType":"text","onlyStatic":true},"copyButton":{"type":"static","value":false,"fieldType":"boolean","onlyStatic":true}},"componentInput":{"eval":"Email","type":"template","value":"Hello ${ctx.username}","fieldType":"template"},"verticalAlignment":"top","horizontalAlignment":"left"}},{"3":{"h":1,"w":2,"x":0,"y":1,"max":{"h":100,"w":3},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"12":{"h":1,"w":12,"x":0,"y":2,"id":"n","max":{"h":100,"w":12},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"id":"n","data":{"id":"n","type":"emailinputcomponent","softWrap":true,"customCss":{"input":{"class":"","style":""}},"configuration":{"placeholder":{"type":"static","value":"Email","fieldType":"text","onlyStatic":true},"defaultValue":{"type":"static","fieldType":"text"}},"verticalAlignment":"center"}},{"3":{"h":1,"w":1,"x":1,"y":0,"max":{"h":100,"w":3},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"12":{"h":1,"w":12,"x":0,"y":3,"id":"o","max":{"h":100,"w":12},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"id":"o","data":{"id":"o","type":"textcomponent","softWrap":true,"customCss":{"text":{"class":"","style":""}},"configuration":{"style":{"type":"static","value":"Label","fieldType":"select","onlyStatic":true,"optionValuesKey":"textStyleOptions"},"tooltip":{"type":"static","value":"","tooltip":"Tooltip text if not empty","fieldType":"text","onlyStatic":true},"copyButton":{"type":"static","value":false,"fieldType":"boolean","onlyStatic":true}},"componentInput":{"eval":"Senha","type":"template","value":"Hello ${ctx.username}","fieldType":"template"},"verticalAlignment":"top","horizontalAlignment":"left"}},{"3":{"h":1,"w":2,"x":0,"y":2,"max":{"h":100,"w":3},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"12":{"h":1,"w":12,"x":0,"y":4,"id":"p","max":{"h":100,"w":12},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"id":"p","data":{"id":"p","type":"passwordinputcomponent","softWrap":true,"customCss":{"input":{"class":"","style":""}},"configuration":{"placeholder":{"type":"static","value":"Password","fieldType":"text","onlyStatic":true}},"verticalAlignment":"center"}},{"3":{"h":1,"w":1,"x":0,"y":3,"max":{"h":100,"w":3},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"12":{"h":2,"w":3,"x":9,"y":5,"id":"q","max":{"h":100,"w":12},"min":{"h":1,"w":1},"fixed":false,"draggable":true,"resizable":true,"customDragger":false,"customResizer":false},"id":"q","data":{"id":"q","type":"buttoncomponent","softWrap":true,"customCss":{"button":{"class":"","style":""}},"recomputeIds":["bg_2","bg_3"],"configuration":{"goto":{"type":"static","value":"","tooltip":"Go to an url on success if not empty","fieldType":"text"},"size":{"type":"static","value":"md","fieldType":"select","onlyStatic":true,"optionValuesKey":"buttonSizeOptions"},"color":{"type":"static","value":"blue","fieldType":"select","onlyStatic":true,"optionValuesKey":"buttonColorOptions"},"label":{"type":"static","value":"Entrar","fieldType":"text"},"disabled":{"expr":"false","type":"eval","fieldType":"boolean"},"afterIcon":{"type":"static","fieldType":"icon-select","onlyStatic":true},"beforeIcon":{"type":"static","value":"LogIn","fieldType":"icon-select","onlyStatic":true},"gotoNewTab":{"type":"static","value":true,"tooltip":"Go to an url on a new tab","fieldType":"boolean"},"fillContainer":{"type":"static","value":false,"fieldType":"boolean","onlyStatic":true},"triggerOnAppLoad":{"type":"static","value":true,"fieldType":"boolean","onlyStatic":true}},"componentInput":{"type":"runnable","fields":{"auth":{"type":"static","value":"$res:f/asset_allocation/supa_asset_allocation","format":"resource-supabase","fieldType":"object"},"hash":{"type":"connected","value":null,"fieldType":"string","connection":{"path":"hash","componentId":"ctx"}},"email":{"type":"connected","value":null,"fieldType":"string","connection":{"path":"result","componentId":"n"}},"password":{"type":"connected","value":null,"fieldType":"string","connection":{"path":"result","componentId":"p"}}},"runnable":{"name":"sign_in","type":"runnableByName","inlineScript":{"path":"f/asset_allocation/auth/sign_in","schema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["auth","email","password","hash"],"properties":{"auth":{"type":"object","format":"resource-supabase","default":null,"description":""},"hash":{"type":"string","default":null,"description":""},"email":{"type":"string","default":null,"description":""},"password":{"type":"string","default":null,"description":""}}},"content":"// import * as wmill from \"https://deno.land/x/windmill@v1.78.0/mod.ts\"\nimport { Resource } from \"https://deno.land/x/windmill@v1.77.0/mod.ts\";\nimport { createClient } from \"https://esm.sh/@supabase/supabase-js@2\";\n\nexport async function main(\n  auth: Resource<\"supabase\">,\n  email: string,\n  password: string,\n  hash: string,\n) {\n  const supabase = createClient(auth.url, auth.key);\n\n  if (email && password) {\n    const { data, error } = await supabase.auth.signInWithPassword({\n      email: email,\n      password: password,\n    });\n    return { data, error };\n  } else if (email) {\n    let { data, error } = await supabase.auth.signInWithOtp({\n      email: email,\n    });\n    if (!error) {\n      error = { \"message\": \"Favor verificar seu email!\" };\n    }\n    return { data, error };\n  } else if (hash) {\n    let info = {};\n    hash.slice(1).split(\"&\").forEach((e) => {\n      let i = e.split(\"=\");\n      info[i[0]] = i[1];\n    });\n    const access_token = info.access_token;\n    const refresh_token = info.refresh_token;\n    const { data, error } = await supabase.auth.setSession({\n      access_token,\n      refresh_token,\n    });\n    return { data, error };\n  } else {\n    return { \"error\": { \"message\": \"Favor digitar email e senha!\" } };\n  }\n}\n","language":"deno"}},"fieldType":"any"},"verticalAlignment":"center","horizontalAlignment":"center"}}]},"fullscreen":false,"hiddenInlineScripts":[{"name":"update_tokens_to_state","fields":{},"autoRefresh":true,"inlineScript":{"path":"f/asset_allocation/auth/update_tokens_to_state","content":"state.access_token = bg_1?.result?.data?.session?.access_token\nstate.refresh_token = bg_1?.result?.data?.session?.refresh_token\nstate.expires_in = bg_1?.result?.data?.session?.expires_in\n","language":"frontend","refreshOn":[{"id":"bg_1","key":"result"}]}},{"name":"refresh_token","fields":{"auth":{"type":"static","value":"$res:f/asset_allocation/supa_asset_allocation","format":"resource-supabase","fieldType":"object"},"expires_in":{"type":"connected","value":null,"fieldType":"number","connection":{"path":"expires_in","componentId":"state"}},"access_token":{"type":"connected","value":null,"fieldType":"string","connection":{"path":"access_token","componentId":"state"}},"refresh_token":{"type":"connected","value":null,"fieldType":"string","connection":{"path":"refresh_token","componentId":"state"}}},"autoRefresh":true,"inlineScript":{"path":"f/asset_allocation/auth/refresh_token","schema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["auth","access_token","refresh_token","expires_in"],"properties":{"auth":{"type":"object","format":"resource-supabase","default":null,"description":""},"expires_in":{"type":"number","default":null,"description":""},"access_token":{"type":"string","default":null,"description":""},"refresh_token":{"type":"string","default":null,"description":""}}},"content":"// import * as wmill from \"https://deno.land/x/windmill@v1.77.0/mod.ts\"\n\nimport { Resource } from \"https://deno.land/x/windmill@v1.77.0/mod.ts\";\nimport { createClient } from \"https://esm.sh/@supabase/supabase-js@2\";\n\nfunction sleep(ms: number) {\n  return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport async function main(\n  auth: Resource<\"supabase\">,\n  access_token: string,\n  refresh_token: string,\n  expires_in: number\n) {\n  if (!access_token && !refresh_token) {\n    return undefined\n  }\n  await sleep(Math.min(expires_in*1000, 2*60*1000))\n  const supabase = createClient(auth.url, auth.key);\n  const { data, error } = await supabase.auth.refreshSession({ refresh_token })\n  return { data, error};\n}","language":"deno"}},{"name":"set_token_to_state_after_sign_in","fields":{},"autoRefresh":false,"inlineScript":{"path":"f/asset_allocation/auth/set_token_to_state_after_sign_in","content":"if (q?.result?.data?.session) {\n  state.access_token = q?.result?.data?.session?.access_token\n  state.refresh_token = q?.result?.data?.session?.refresh_token\n  state.expires_in = q?.result?.data?.session?.expires_in\n  state.message = ''\n} else if (q?.result?.error) {\n  state.access_token = null\n  state.refresh_token = null\n  state.expires_in = null\n  state.message = q?.result?.error.message\n}\n\n","language":"frontend","refreshOn":[{"id":"q","key":"result"}]}},{"name":"control_tab","fields":{},"autoRefresh":true,"inlineScript":{"path":"f/asset_allocation/auth/control_tab","content":"if (!a.selectedTabIndex && ((state.access_token == undefined) || (state.refresh_token == undefined))) {\r\n  setTab('a', 0)\r\n} else {\r\n  setTab('a', 1)\r\n}","language":"frontend","refreshOn":[{"id":"a","key":"selectedTabIndex"},{"id":"state","key":"access_token"},{"id":"state","key":"refresh_token"}]}}],"unusedInlineScripts":[]},"description":"application protected by auth using supabase, sign in using email/password or magic link and auto refresh tokens","vcreated_at":"2023-03-16T21:00:29.480Z","vcreated_by":"josé governo425","comments":[]}}