Skip to content

Commit

Permalink
fix: https on non-localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnabXD committed Jul 13, 2022
1 parent 0fdc4d8 commit 69aae71
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pages/api/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
clientSecret: APP_SECRET,
});

const redirectUri = `http://${req.headers.host}/api/auth/token`;
const redirectUri = req.headers.host?.includes("localhost")
? `http://${req.headers.host}/api/auth/token`
: `https://${req.headers.host}/api/auth/token`;
const authUri = await dbx.getAuthenticationUrl(
redirectUri,
undefined,
Expand Down
4 changes: 3 additions & 1 deletion pages/api/auth/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
clientSecret: APP_SECRET,
});

const redirectUri = `http://${req.headers.host}/api/auth/token`;
const redirectUri = req.headers.host?.includes("localhost")
? `http://${req.headers.host}/api/auth/token`
: `https://${req.headers.host}/api/auth/token`;
const code = req.query.code as string;

const refreshToken = await dbx.getAccessTokenFromCode(redirectUri, code);
Expand Down

0 comments on commit 69aae71

Please sign in to comment.