Skip to content

Commit

Permalink
fix(auth): fix authenticating with cookie storage (#372)
Browse files Browse the repository at this point in the history
* fix(auth): fix authenticating with cookie storage

* bump to studio v0.0.56

* fix typo

* undo version bump
  • Loading branch information
laurentlp committed Jul 26, 2022
1 parent c05cdb4 commit 188fb5b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/studio-be/api.rest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


### Send a request using Converse
GET http://localhost:3002/api/v1/studio/welcome-bot/env.js
GET http://localhost:3002/api/v1/studio/welcome-bot/public-env.js
Content-Type: application/json

{
Expand Down
5 changes: 2 additions & 3 deletions packages/studio-be/src/core/app/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { debugRequestMw, resolveStudioAsset } from './server-utils'
const BASE_API_PATH = '/api/v1'

const getSocketTransports = (config: BotpressConfig): string[] => {
const transports = _.filter(config.httpServer.socketTransports, t => ['websocket', 'polling'].includes(t))
const transports = _.filter(config.httpServer.socketTransports, (t) => ['websocket', 'polling'].includes(t))
return transports && transports.length ? transports : ['websocket', 'polling']
}

Expand Down Expand Up @@ -147,7 +147,6 @@ export class HTTPServer {

return {
SEND_USAGE_STATS: config!.sendUsageStats,
USE_JWT_COOKIES: process.USE_JWT_COOKIES,
EXPERIMENTAL: config.experimental,
SOCKET_TRANSPORTS: getSocketTransports(config),
SHOW_POWERED_BY: !!config.showPoweredBy,
Expand Down Expand Up @@ -285,7 +284,7 @@ export class HTTPServer {
process.LOCAL_URL = `http://localhost:${process.PORT}${process.ROOT_PATH}`
process.EXTERNAL_URL = process.env.EXTERNAL_URL || config.externalUrl || `http://${process.HOST}:${process.PORT}`

await Promise.fromCallback(callback => {
await Promise.fromCallback((callback) => {
this.httpServer.listen(process.PORT, undefined, config.backlog, () => callback(undefined))
})

Expand Down
5 changes: 3 additions & 2 deletions packages/studio-be/src/studio/studio-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class StudioRouter extends CustomRouter {

app.use('/api/internal', this.internalRouter.router)

app.use(rewrite('/studio/:botId/*branding.js', '/api/v1/studio/:botId/branding.js'))
app.use(rewrite('/studio/:botId/*public-env.js', '/api/v1/studio/:botId/public-env.js'))
app.use(rewrite('/studio/:botId/*env', '/api/v1/studio/:botId/env'))

// TODO: Temporary in case we forgot to change it somewhere
Expand Down Expand Up @@ -216,7 +216,7 @@ export class StudioRouter extends CustomRouter {
* Do not return sensitive information there. These must be accessible by unauthenticated users
*/
this.router.get(
'/branding.js',
'/public-env.js',
this.asyncMiddleware(async (req, res) => {
const { botId } = req.params

Expand All @@ -232,6 +232,7 @@ export class StudioRouter extends CustomRouter {
window.APP_NAME = "${removeHtmlChars(branding.title)}";
window.APP_FAVICON = "${removeHtmlChars(branding.favicon)}";
window.APP_CUSTOM_CSS = "${removeHtmlChars(branding.customCss)}";
window.USE_JWT_COOKIES = ${process.USE_JWT_COOKIES};
})(typeof window != 'undefined' ? window : {})
`

Expand Down
2 changes: 1 addition & 1 deletion packages/studio-ui/src/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<script src="branding.js"></script>
<script src="public-env.js"></script>
<script>
window.ROOT_PATH = ''
</script>
Expand Down

0 comments on commit 188fb5b

Please sign in to comment.