File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -68,8 +68,23 @@ export const useConnector = createSharedComposable(function useConnector() {
6868
6969 const baseUrl = computed ( ( ) => `http://localhost:${ config . value ?. port ?? DEFAULT_PORT } ` )
7070
71- // Load persisted config on client
71+ const route = useRoute ( )
72+ const router = useRouter ( )
73+
7274 onMounted ( ( ) => {
75+ const urlToken = route . query . token as string | undefined
76+ const urlPort = route . query . port as string | undefined
77+
78+ if ( urlToken ) {
79+ const { token : _ , port : __ , ...cleanQuery } = route . query
80+ router . replace ( { query : cleanQuery } )
81+
82+ // Connect with URL params
83+ const port = urlPort ? Number . parseInt ( urlPort , 10 ) : DEFAULT_PORT
84+ connect ( urlToken , port )
85+ return
86+ }
87+
7388 const stored = localStorage . getItem ( STORAGE_KEY )
7489 if ( stored ) {
7590 try {
Original file line number Diff line number Diff line change @@ -58,13 +58,15 @@ export function logMessage(message: string): void {
5858 * Show the connection token in a nice box
5959 */
6060export function showToken ( token : string , port : number ) : void {
61+ const connectUrl = `https://npmx.dev/?token=${ token } &port=${ port } `
62+
6163 p . note (
6264 [
63- `Token : ${ pc . bold ( pc . cyan ( token ) ) } ` ,
65+ `Open : ${ pc . bold ( pc . underline ( pc . cyan ( connectUrl ) ) ) } ` ,
6466 '' ,
65- pc . dim ( `Server: http://localhost: ${ port } ` ) ,
67+ pc . dim ( `Or paste token manually: ${ token } ` ) ,
6668 ] . join ( '\n' ) ,
67- 'Paste this token in npmx.dev to connect' ,
69+ 'Click to connect' ,
6870 )
6971}
7072
You can’t perform that action at this time.
0 commit comments