diff --git a/common/user.ts b/common/user.ts
index b490ab0c..5ab07d35 100644
--- a/common/user.ts
+++ b/common/user.ts
@@ -71,6 +71,7 @@ export type PrivateUser = {
twitchName: string
controlToken: string
botEnabled?: boolean
+ needsRelinking?: boolean
}
}
diff --git a/web/pages/profile.tsx b/web/pages/profile.tsx
index c038fd11..2c095db6 100644
--- a/web/pages/profile.tsx
+++ b/web/pages/profile.tsx
@@ -2,9 +2,11 @@ import { RefreshIcon } from '@heroicons/react/outline'
import { PrivateUser, User } from 'common/user'
import { cleanDisplayName, cleanUsername } from 'common/util/clean-username'
import { formatMoney } from 'common/util/format'
+import Link from 'next/link'
import React, { useState } from 'react'
import Textarea from 'react-expanding-textarea'
import { AddFundsButton } from 'web/components/add-funds-button'
+import { ConfirmationButton } from 'web/components/confirmation-button'
import { Col } from 'web/components/layout/col'
import { Row } from 'web/components/layout/row'
import { Page } from 'web/components/page'
@@ -16,7 +18,11 @@ import { generateNewApiKey } from 'web/lib/api/api-key'
import { changeUserInfo } from 'web/lib/firebase/api'
import { redirectIfLoggedOut } from 'web/lib/firebase/server-auth'
import { uploadImage } from 'web/lib/firebase/storage'
-import { getUserAndPrivateUser, updateUser } from 'web/lib/firebase/users'
+import {
+ getUserAndPrivateUser,
+ updatePrivateUser,
+ updateUser,
+} from 'web/lib/firebase/users'
export const getServerSideProps = redirectIfLoggedOut('/', async (_, creds) => {
return { props: { auth: await getUserAndPrivateUser(creds.uid) } }
@@ -91,10 +97,15 @@ export default function ProfilePage(props: {
}
}
- const updateApiKey = async (e: React.MouseEvent) => {
+ const updateApiKey = async (e?: React.MouseEvent) => {
const newApiKey = await generateNewApiKey(user.id)
setApiKey(newApiKey ?? '')
- e.preventDefault()
+ e?.preventDefault()
+
+ if (!privateUser.twitchInfo) return
+ await updatePrivateUser(privateUser.id, {
+ twitchInfo: { ...privateUser.twitchInfo, needsRelinking: true },
+ })
}
const fileHandler = async (event: any) => {
@@ -227,12 +238,36 @@ export default function ProfilePage(props: {
value={apiKey}
readOnly
/>
- ,
+ }}
+ submitBtn={{
+ label: 'Update key',
+ className: 'btn-primary',
+ }}
+ onSubmitWithSuccess={async () => {
+ updateApiKey()
+ return true
+ }}
>
-