-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
refactor: code base improvements #959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8331370
chore: fix casing of OAuth
balazsorban44 d04185c
refacotr: simplify default callbacks lib file
balazsorban44 690c55b
refactor: use native URL instead of string concats
balazsorban44 b63857c
refactor: move redirect to res.redirect, done to res.end
balazsorban44 740b3a8
refactor: move options to req
balazsorban44 24b08df
refactor: improve IntelliSense, name all functions
balazsorban44 aa292dc
Merge branch 'canary' into feature/misc-improvements
balazsorban44 0bac6cf
fix(lint): fix lint errors
balazsorban44 a0ebbb2
refactor: remove jwt-decode dependency
balazsorban44 27ecee8
refactor: refactor some callbacks to Promises
balazsorban44 0c9f6f0
revert: "refactor: use native URL instead of string concats"
7b4d8c2
chore: misc changes
70bb032
Merge branch 'canary' into feature/misc-improvements
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import logger from './logger' | ||
|
||
/** | ||
* Simple universal (client/server) function to split host and path. | ||
* It can also take a url (either URL or a string) and parses it correctly. | ||
* @returns {URL} | ||
*/ | ||
function baseUrl (url) { | ||
let _url = url || process.env.NEXTAUTH_URL || process.env.VERCEL_URL | ||
if (typeof _url !== 'string' && !(_url instanceof URL)) { | ||
throw new Error('baseUrl must be either a valid URL object or a valid string URL') | ||
} | ||
const defaultUrl = 'http://localhost:3000/api/auth' | ||
_url = _url || defaultUrl | ||
try { | ||
const parsedUrl = new URL(_url) | ||
if (parsedUrl.pathname === '/') { | ||
parsedUrl.pathname = '/api/auth' | ||
} | ||
parsedUrl.pathname = parsedUrl.pathname.replace(/\/$/, '') | ||
parsedUrl.href = parsedUrl.href.replace(/\/$/, '') | ||
balazsorban44 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return parsedUrl | ||
} catch (error) { | ||
logger.error('INVALID_URL', _url, error) | ||
return new URL(defaultUrl) | ||
} | ||
} | ||
|
||
export default baseUrl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.