Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/auth-jwt-cookie' into feat/…
Browse files Browse the repository at this point in the history
…auth-jwt-cookie
  • Loading branch information
kyle-ssg committed Oct 2, 2024
2 parents 2b20836 + 4034636 commit e07ad60
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
9 changes: 5 additions & 4 deletions api/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ def project_overrides(request):
"amplitude": "AMPLITUDE_API_KEY",
"api": "API_URL",
"assetURL": "ASSET_URL",
"cookieAuthEnabled": "COOKIE_AUTH_ENABLED",
"cookieSameSite": "COOKIE_SAME_SITE",
"crispChat": "CRISP_CHAT_API_KEY",
"disableAnalytics": "DISABLE_ANALYTICS_FEATURES",
"flagsmith": "FLAGSMITH_ON_FLAGSMITH_API_KEY",
"flagsmithAnalytics": "FLAGSMITH_ANALYTICS",
"flagsmithRealtime": "ENABLE_FLAGSMITH_REALTIME",
"flagsmithClientAPI": "FLAGSMITH_ON_FLAGSMITH_API_URL",
"ga": "GOOGLE_ANALYTICS_API_KEY",
"flagsmithRealtime": "ENABLE_FLAGSMITH_REALTIME",
"fpr": "FIRST_PROMOTER_ID",
"ga": "GOOGLE_ANALYTICS_API_KEY",
"githubAppURL": "GITHUB_APP_URL",
"headway": "HEADWAY_API_KEY",
"hideInviteLinks": "DISABLE_INVITE_LINKS",
"linkedinPartnerTracking": "LINKEDIN_PARTNER_TRACKING",
Expand All @@ -54,8 +57,6 @@ def project_overrides(request):
"preventSignup": "PREVENT_SIGNUP",
"sentry": "SENTRY_API_KEY",
"useSecureCookies": "USE_SECURE_COOKIES",
"cookieSameSite": "COOKIE_SAME_SITE",
"githubAppURL": "GITHUB_APP_URL",
}

override_data = {
Expand Down
1 change: 0 additions & 1 deletion frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ module.exports = {
'toast': true,
'window': true,
'zE': true,
'COOKIE_AUTH_ENABLED': true,
},
'ignorePatterns': ['server/index.js', 'next.config.js', 'babel.config.js'],
'parser': '@typescript-eslint/parser',
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/data/base/_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const getQueryString = (params) => {
module.exports = {
_request(method, _url, data, headers = {}) {
const options = {
credentials: COOKIE_AUTH_ENABLED ? 'include' : undefined,
credentials: Project.cookieAuthEnabled ? 'include' : undefined,
headers: {
'Accept': 'application/json',
...headers,
Expand Down
6 changes: 3 additions & 3 deletions frontend/common/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const baseApiOptions = (queryArgs?: Partial<FetchBaseQueryArgs>) => {
| 'extractRehydrationInfo'
> = {
baseQuery: fetchBaseQuery({
credentials: COOKIE_AUTH_ENABLED ? 'include' : 'omit', // 'include' for cookies, 'omit' if not
credentials: Project.cookieAuthEnabled ? 'include' : 'omit', // 'include' for cookies, 'omit' if not
baseUrl: Project.api,
prepareHeaders: async (headers, { endpoint, getState }) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -30,10 +30,10 @@ export const baseApiOptions = (queryArgs?: Partial<FetchBaseQueryArgs>) => {
) {
try {
const token = _data.token
if (token && !COOKIE_AUTH_ENABLED) {
if (token && !Project.cookieAuthEnabled) {
headers.set('Authorization', `Token ${token}`)
}
} catch (e) {}
} catch (e) { }
}

return headers
Expand Down
1 change: 0 additions & 1 deletion frontend/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { TooltipProps } from './web/components/Tooltip'

export declare const openModal: (name?: string) => Promise<void>
declare global {
const COOKIE_AUTH_ENABLED: boolean
const openModal: (
title: ReactNode,
body?: ReactNode,
Expand Down
21 changes: 11 additions & 10 deletions frontend/web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createBrowserHistory } from 'history'
import ToastMessages from './project/toast'
import routes from './routes'
import Utils from 'common/utils/utils'
import Project from 'common/project'
import AccountStore from 'common/stores/account-store'
import data from 'common/data/base/_data'

Expand All @@ -26,18 +27,18 @@ if (params.token) {
}

// Render the React application to the DOM
const res = COOKIE_AUTH_ENABLED ? 'true' : API.getCookie('t')
const res = Project.cookieAuthEnabled ? 'true' : API.getCookie('t')

const event = API.getEvent()
if (event) {
try {
data
.post('/api/event', JSON.parse(event))
.catch(() => {})
.catch(() => { })
.finally(() => {
API.setEvent('')
})
} catch (e) {}
} catch (e) { }
}

const isInvite = document.location.href.includes('invite')
Expand Down Expand Up @@ -85,13 +86,13 @@ const isWidget = document.location.href.includes('/widget')
if (!E2E && Project.crispChat && !isWidget) {
window.$crisp = []
window.CRISP_WEBSITE_ID = Project.crispChat
;(function () {
const d = document
const s = d.createElement('script')
s.src = 'https://client.crisp.chat/l.js'
s.async = 1
d.getElementsByTagName('head')[0].appendChild(s)
})()
; (function () {
const d = document
const s = d.createElement('script')
s.src = 'https://client.crisp.chat/l.js'
s.async = 1
d.getElementsByTagName('head')[0].appendChild(s)
})()
}

if (!E2E && Project.zendesk && !isWidget) {
Expand Down
1 change: 0 additions & 1 deletion frontend/webpack/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module.exports = [
E2E: process.env.E2E,
SENTRY_RELEASE_VERSION: true,
DYNATRACE_URL: !!process.env.DYNATRACE_URL && JSON.stringify(process.env.DYNATRACE_URL),
COOKIE_AUTH_ENABLED: !!process.env.COOKIE_AUTH_ENABLED,
}),
// // Fixes warning in moment-with-locales.min.js
// // Module not found: Error: Can't resolve './locale' in ...
Expand Down

0 comments on commit e07ad60

Please sign in to comment.