Skip to content

Commit 06608b1

Browse files
committed
keep verification state in PENDING instead of FAILED; use _snverify as TXT record to be checked; light cleanup
1 parent 21a15d9 commit 06608b1

File tree

4 files changed

+30
-42
lines changed

4 files changed

+30
-42
lines changed

api/resolvers/domain.js

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,41 +37,32 @@ export default {
3737
if (existing && existing.domain === domain && existing.status !== 'HOLD') {
3838
throw new GqlInputError('domain already set')
3939
}
40+
41+
const initializeDomain = {
42+
domain,
43+
status: 'PENDING',
44+
verification: {
45+
dns: {
46+
state: 'PENDING',
47+
cname: 'stacker.news',
48+
txt: randomBytes(32).toString('base64')
49+
},
50+
ssl: {
51+
state: 'WAITING',
52+
arn: null,
53+
cname: null,
54+
value: null
55+
}
56+
}
57+
}
58+
4059
const updatedDomain = await models.customDomain.upsert({
4160
where: { subName },
4261
update: {
43-
domain,
44-
status: 'PENDING',
45-
verification: {
46-
dns: {
47-
state: 'PENDING',
48-
cname: 'stacker.news',
49-
txt: randomBytes(32).toString('base64')
50-
},
51-
ssl: {
52-
state: 'WAITING',
53-
arn: null,
54-
cname: null,
55-
value: null
56-
}
57-
}
62+
...initializeDomain
5863
},
5964
create: {
60-
domain,
61-
status: 'PENDING',
62-
verification: {
63-
dns: {
64-
state: 'PENDING',
65-
cname: 'stacker.news',
66-
txt: randomBytes(32).toString('base64')
67-
},
68-
ssl: {
69-
state: 'WAITING',
70-
arn: null,
71-
cname: null,
72-
value: null
73-
}
74-
},
65+
...initializeDomain,
7566
sub: {
7667
connect: { name: subName }
7768
}

components/territory-domains.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,19 @@ const getStatusBadge = (status) => {
7474
switch (status) {
7575
case 'VERIFIED':
7676
return <Badge bg='success'>DNS verified</Badge>
77-
case 'PENDING':
77+
default:
7878
return <Badge bg='warning'>DNS pending</Badge>
79-
case 'FAILED':
80-
return <Badge bg='danger'>DNS failed</Badge>
8179
}
8280
}
8381

8482
const getSSLStatusBadge = (status) => {
8583
switch (status) {
8684
case 'VERIFIED':
8785
return <Badge bg='success'>SSL verified</Badge>
88-
case 'PENDING':
89-
return <Badge bg='warning'>SSL pending</Badge>
90-
case 'FAILED':
91-
return <Badge bg='danger'>SSL failed</Badge>
9286
case 'WAITING':
9387
return <Badge bg='info'>SSL waiting</Badge>
88+
default:
89+
return <Badge bg='warning'>SSL pending</Badge>
9490
}
9591
}
9692

@@ -172,7 +168,7 @@ const DomainGuidelines = ({ customDomain }) => {
172168
{dnsRecord(domain || 'www', verification?.dns?.cname)}
173169
<hr />
174170
<h6>TXT</h6>
175-
{dnsRecord(domain || 'www', verification?.dns?.txt)}
171+
{dnsRecord(`_snverify.${domain}`, verification?.dns?.txt)}
176172
</div>
177173
)}
178174
{verification?.ssl?.state === 'PENDING' && (

lib/domain-verification.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export async function getValidationValues (certificateArn) {
6161
// Verify the DNS records for a custom domain
6262
export async function verifyDomainDNS (domainName, verificationTxt, verificationCname) {
6363
const cname = verificationCname || process.env.NEXT_PUBLIC_URL.replace(/^https?:\/\//, '')
64+
const txtHost = `_snverify.${domainName}`
6465
const result = {
6566
txtValid: false,
6667
cnameValid: false,
@@ -72,7 +73,7 @@ export async function verifyDomainDNS (domainName, verificationTxt, verification
7273

7374
// TXT Records checking
7475
try {
75-
const txtRecords = await dnsPromises.resolve(domainName, 'TXT')
76+
const txtRecords = await dnsPromises.resolve(txtHost, 'TXT')
7677
const txtText = txtRecords.flat().join(' ')
7778

7879
// the TXT record should include the verificationTxt that we have in the database

worker/domainVerification.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async function verifyDomain (domain, models) {
5151
await updateCertificateStatus(data)
5252
}
5353

54-
if (data.verification?.dns?.state === 'FAILED' || data.verification?.ssl?.state === 'FAILED') {
54+
if (data.verification?.dns?.state === 'PENDING' || data.verification?.ssl?.state === 'PENDING') {
5555
data.failedAttempts += 1
5656
// exponential backoff at the 11th attempt is roughly 48 hours
5757
if (data.failedAttempts > 11) {
@@ -71,7 +71,7 @@ async function verifyDNS (data) {
7171
const { txtValid, cnameValid } = await verifyDomainDNS(data.domain, data.verification.dns.txt)
7272
console.log(`${data.domain}: TXT ${txtValid ? 'valid' : 'invalid'}, CNAME ${cnameValid ? 'valid' : 'invalid'}`)
7373

74-
data.verification.dns.state = txtValid && cnameValid ? 'VERIFIED' : 'FAILED'
74+
data.verification.dns.state = txtValid && cnameValid ? 'VERIFIED' : 'PENDING'
7575
return data
7676
}
7777

@@ -96,7 +96,7 @@ async function issueCertificate (data) {
9696
}
9797
}
9898
} else {
99-
data.verification.ssl.state = 'FAILED'
99+
data.verification.ssl.state = 'PENDING'
100100
}
101101

102102
return data

0 commit comments

Comments
 (0)